summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Esser <besser82@fedoraproject.org>2021-08-04 11:34:51 +0200
committerBjörn Esser <besser82@fedoraproject.org>2021-08-04 11:36:54 +0200
commit7323345e82f66515155db9a8d0522722229e866c (patch)
tree53d61bc659db6db68ec86687511e78fc49f12afd
parentbb33c6da5a05ed7035a3ae3e62184568a51f0fb3 (diff)
downloadlibxcrypt-7323345e82f66515155db9a8d0522722229e866c.tar.gz
libxcrypt-7323345e82f66515155db9a8d0522722229e866c.tar.bz2
libxcrypt-7323345e82f66515155db9a8d0522722229e866c.zip
test/short-outbuf.c: Fix 'INCOMPATIBLE_CAST' found by Covscan.
CWE-188: Reliance on integer endianness (INCOMPATIBLE_CAST) incompatible_cast: Pointer &j points to an object whose effective type is unsigned long (64 bits, unsigned) but is dereferenced as a narrower int (32 bits, signed). This may lead to unexpected results depending on machine endianness.
-rw-r--r--test/short-outbuf.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/test/short-outbuf.c b/test/short-outbuf.c
index 60ad3f1..8942292 100644
--- a/test/short-outbuf.c
+++ b/test/short-outbuf.c
@@ -43,12 +43,13 @@ main (void)
for (size_t i = 0; i < ARRAY_SIZE (testcases); i++)
{
- size_t j = i + 1;
- char *outbuf = malloc (sizeof (char) * j);
+ size_t s = i + 1;
+ int j = (int) s;
+ char *outbuf = malloc (sizeof (char) * s);
- crypt_rn ("@@", "@@", outbuf, (int) j);
+ crypt_rn ("@@", "@@", outbuf, j);
- if (!strncmp (testcases[i].exp_rn, outbuf, j))
+ if (!strncmp (testcases[i].exp_rn, outbuf, s))
{
strcpy (result, "PASS");
}
@@ -59,9 +60,9 @@ main (void)
}
printf ("Test %zu.0: %s, expected: \"%-2s\", got: \"%-2s\"\n",
- j, result, testcases[i].exp_rn, outbuf);
+ s, result, testcases[i].exp_rn, outbuf);
- crypt_ra ("@@", "@@", (void **) &outbuf, (int *) &j);
+ crypt_ra ("@@", "@@", (void **) &outbuf, &j);
if (!strncmp (testcases[i].exp_ra, outbuf, strlen(outbuf)))
{
@@ -74,7 +75,7 @@ main (void)
}
printf ("Test %zu.1: %s, expected: \"%-2s\", got: \"%-2s\"\n",
- i + 1, result, testcases[i].exp_ra, outbuf);
+ s, result, testcases[i].exp_ra, outbuf);
free (outbuf);
}