These are things that showed up in valgrind while running the tests.
size_t length)
{
char *ret;
- size_t len;
-
- len = strlen (data);
- if (length > len)
- length = len;
- ret = memdup (data, length + 1);
- if (ret != NULL)
+ ret = malloc (length + 1);
+ if (ret != NULL) {
+ strncpy (ret, data, length);
ret[length] = 0;
+ }
return ret;
}
}
}
+static void
+test_strndup (CuTest *tc)
+{
+ char unterminated[] = { 't', 'e', 's', 't', 'e', 'r', 'o', 'n', 'i', 'o' };
+ char *res;
+
+ res = strndup (unterminated, 6);
+ CuAssertStrEquals (tc, res, "tester");
+ free (res);
+
+ res = strndup ("test", 6);
+ CuAssertStrEquals (tc, res, "test");
+ free (res);
+}
+
int
main (void)
{
int ret;
SUITE_ADD_TEST (suite, test_basename);
+ SUITE_ADD_TEST (suite, test_strndup);
CuSuiteRun (suite);
CuSuiteSummary (suite, output);
CuAssertTrue (cu, input != NULL);
memset (input, 'a', 1000000);
- p11_hash_sha1 (checksum, input, strlen (input), NULL);
+ p11_hash_sha1 (checksum, input, 1000000, NULL);
CuAssertTrue (cu, memcmp (expected, checksum, P11_HASH_SHA1_LEN) == 0);
}
uint32_t first, second;
p11_hash_murmur2 ((unsigned char *)&first,
- "this is the long input!", 23,
+ "this is the long input!", (size_t)23,
NULL);
p11_hash_murmur2 ((unsigned char *)&second,
- "this", 4,
- " ", 1,
- "is ", 3,
- "the long ", 9,
- "in", 2,
- "p", 1,
- "u", 1,
- "t", 1,
- "!", 1,
+ "this", (size_t)4,
+ " ", (size_t)1,
+ "is ", (size_t)3,
+ "the long ", (size_t)9,
+ "in", (size_t)2,
+ "p", (size_t)1,
+ "u", (size_t)1,
+ "t", (size_t)1,
+ "!", (size_t)1,
NULL);
CuAssertIntEquals (cu, first, second);
for (j = 1; j < num; j++) {
assert (buckets[j]->elem); /* checked above */
at = binary_search (buckets[j]->elem, 0, buckets[j]->num, handle);
- if (buckets[j]->elem[at] != handle) {
+ if (at >= buckets[j]->num || buckets[j]->elem[at] != handle) {
handle = 0;
break;
}
free (check);
/* A double check of this method */
+ one = 0UL;
+ check = &one;
CuAssertTrue (tc, !handles_are (check, 29292929, 0UL));
CuAssertTrue (tc, !handles_are (NULL, 0UL));