diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
commit | 0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch) | |
tree | 2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /string/tester.c | |
parent | 7d58530341304d403a6626d7f7a1913165fe2f32 (diff) | |
download | glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.bz2 glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip |
2.5-18.1
Diffstat (limited to 'string/tester.c')
-rw-r--r-- | string/tester.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/string/tester.c b/string/tester.c index 5f0a851104..cccef3ad9d 100644 --- a/string/tester.c +++ b/string/tester.c @@ -1,5 +1,5 @@ /* Tester for string functions. - Copyright (C) 1995-2000, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1995-2001, 2003, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -34,10 +34,6 @@ #include <strings.h> #include <fcntl.h> -#ifndef HAVE_GNU_LD -#define _sys_nerr sys_nerr -#define _sys_errlist sys_errlist -#endif #define STREQ(a, b) (strcmp((a), (b)) == 0) @@ -348,6 +344,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 @@ -368,6 +367,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 @@ -434,6 +435,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"; @@ -1386,6 +1410,9 @@ main (void) /* strlen. */ test_strlen (); + /* strnlen. */ + test_strnlen (); + /* strchr. */ test_strchr (); |