Skip to content

Commit 56856f0

Browse files
author
tb
committed
bn_unit: appease coverity
Apparently, the '0' in memset(a, '0', size - 1); could be a typo for '\0'. Randomize the decimal digit to make the intent clear. CID 377009
1 parent 43aa658 commit 56856f0

File tree

1 file changed

+6
-2
lines changed
  • src/regress/lib/libcrypto/bn/general

1 file changed

+6
-2
lines changed

src/regress/lib/libcrypto/bn/general/bn_unit.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: bn_unit.c,v 1.3 2022/11/23 08:01:05 tb Exp $ */
1+
/* $OpenBSD: bn_unit.c,v 1.4 2022/11/23 08:58:34 tb Exp $ */
22

33
/*
44
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
@@ -45,6 +45,7 @@ test_bn_print_null_derefs(void)
4545
size_t size = INT_MAX / 4 + 4;
4646
size_t datalimit = (size + 500 * 1024) / 1024;
4747
char *a;
48+
char digit;
4849
int failed = 0;
4950

5051
if ((a = malloc(size)) == NULL) {
@@ -53,7 +54,10 @@ test_bn_print_null_derefs(void)
5354
return 0;
5455
}
5556

56-
memset(a, '0', size - 1);
57+
/* Fill with a random digit since coverity doesn't like us using '0'. */
58+
digit = '0' + arc4random_uniform(10);
59+
60+
memset(a, digit, size - 1);
5761
a[size - 1] = '\0';
5862

5963
failed |= test_bn_print_wrapper(a, size, "BN_dec2bn", BN_dec2bn);

0 commit comments

Comments
 (0)