|
@@ -337,6 +337,9 @@ test_strncat (void)
|
|
|
|
|
|
(void) strncat (one, "gh", 2);
|
|
|
equal (one, "abcdgh", 12);
|
|
|
+
|
|
|
+ (void) strncat (one, "ij", (size_t)-1);
|
|
|
+ equal (one, "abcdghij", 13);
|
|
|
}
|
|
|
|
|
|
static void
|
|
@@ -357,6 +360,8 @@ test_strncmp (void)
|
|
|
check (strncmp ("abce", "abc", 3) == 0, 11);
|
|
|
check (strncmp ("abcd", "abce", 4) < 0, 12);
|
|
|
check (strncmp ("abc", "def", 0) == 0, 13);
|
|
|
+ check (strncmp ("abc", "", (size_t)-1) > 0, 14);
|
|
|
+ check (strncmp ("abc", "abc", (size_t)-2) == 0, 15);
|
|
|
}
|
|
|
|
|
|
static void
|
|
@@ -422,6 +427,29 @@ test_strlen (void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void
|
|
|
+test_strnlen (void)
|
|
|
+{
|
|
|
+ it = "strnlen";
|
|
|
+ check (strnlen ("", 10) == 0, 1);
|
|
|
+ check (strnlen ("a", 10) == 1, 2);
|
|
|
+ check (strnlen ("abcd", 10) == 4, 3);
|
|
|
+ check (strnlen ("foo", (size_t)-1) == 3, 4);
|
|
|
+
|
|
|
+ {
|
|
|
+ char buf[4096];
|
|
|
+ int i;
|
|
|
+ char *p;
|
|
|
+ for (i=0; i < 0x100; i++)
|
|
|
+ {
|
|
|
+ p = (char *) ((unsigned long int)(buf + 0xff) & ~0xff) + i;
|
|
|
+ strcpy (p, "OK");
|
|
|
+ strcpy (p+3, "BAD/WRONG");
|
|
|
+ check (strnlen (p, 100) == 2, 5+i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
static void
|
|
|
test_strchr (void)
|
|
|
{
|
|
@@ -1329,6 +1357,9 @@ main (void)
|
|
|
|
|
|
test_strlen ();
|
|
|
|
|
|
+
|
|
|
+ test_strnlen ();
|
|
|
+
|
|
|
|
|
|
test_strchr ();
|
|
|
|