summaryrefslogtreecommitdiffstats
path: root/test/string
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2005-08-31 22:27:45 +0000
committerMike Frysinger <vapier@gentoo.org>2005-08-31 22:27:45 +0000
commitddb323338544f173afd4d574fb0bb3379d3bd556 (patch)
treeab43ad4d0f4334183939aa5f6731b77c455307d8 /test/string
parentd4bfde8b5f70afa6a51011611abc40d393e59385 (diff)
downloaduClibc-alpine-ddb323338544f173afd4d574fb0bb3379d3bd556.tar.bz2
uClibc-alpine-ddb323338544f173afd4d574fb0bb3379d3bd556.tar.xz
add (size_t)-1 border case tests for strncat and strncmp, and add a bunch of tests for strnlen based on strlen
Diffstat (limited to 'test/string')
-rw-r--r--test/string/string.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/string/string.c b/test/string/string.c
index e23ee6279..60caddf99 100644
--- a/test/string/string.c
+++ b/test/string/string.c
@@ -337,6 +337,9 @@ test_strncat (void)
(void) strncat (one, "gh", 2);
equal (one, "abcdgh", 12); /* Count and length equal. */
+
+ (void) strncat (one, "ij", (size_t)-1); /* set sign bit in count */
+ equal (one, "abcdghij", 13);
}
static void
@@ -357,6 +360,8 @@ test_strncmp (void)
check (strncmp ("abce", "abc", 3) == 0, 11); /* Count == length. */
check (strncmp ("abcd", "abce", 4) < 0, 12); /* Nudging limit. */
check (strncmp ("abc", "def", 0) == 0, 13); /* Zero count. */
+ check (strncmp ("abc", "", (size_t)-1) > 0, 14); /* set sign bit in count */
+ check (strncmp ("abc", "abc", (size_t)-2) == 0, 15);
}
static void
@@ -423,6 +428,29 @@ test_strlen (void)
}
static void
+test_strnlen (void)
+{
+ it = "strnlen";
+ check (strnlen ("", 10) == 0, 1); /* Empty. */
+ check (strnlen ("a", 10) == 1, 2); /* Single char. */
+ check (strnlen ("abcd", 10) == 4, 3); /* Multiple chars. */
+ check (strnlen ("foo", (size_t)-1) == 3, 4); /* limits of n. */
+
+ {
+ 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)
{
it = "strchr";
@@ -1329,6 +1357,9 @@ main (void)
/* strlen. */
test_strlen ();
+ /* strnlen. */
+ test_strnlen ();
+
/* strchr. */
test_strchr ();