diff options
author | Ulrich Drepper <drepper@redhat.com> | 2001-08-23 01:10:57 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2001-08-23 01:10:57 +0000 |
commit | a5ae1fc2d2aa06f8958532d7cad8612dda06dd50 (patch) | |
tree | cf61a99fa5541252a681d901e28d7d51b4ea03f0 /string/stratcliff.c | |
parent | c3201035708fd6511fabd96c1097e7559709bd77 (diff) | |
download | glibc-a5ae1fc2d2aa06f8958532d7cad8612dda06dd50.zip glibc-a5ae1fc2d2aa06f8958532d7cad8612dda06dd50.tar.gz glibc-a5ae1fc2d2aa06f8958532d7cad8612dda06dd50.tar.bz2 |
(main): Add strncpy test.
Diffstat (limited to 'string/stratcliff.c')
-rw-r--r-- | string/stratcliff.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/string/stratcliff.c b/string/stratcliff.c index 44a2613..f25ae0c 100644 --- a/string/stratcliff.c +++ b/string/stratcliff.c @@ -1,5 +1,5 @@ /* Test for string function add boundaries of usable memory. - Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 1999, 2000, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -192,6 +192,33 @@ main (int argc, char *argv[]) } } + /* strncpy test */ + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + { + for (inner = MAX (outer, size - 64); inner < size; ++inner) + { + size_t len; + + adr[inner] = '\0'; + + for (len = 0; len < size - outer + 64; ++len) + { + if (strncpy (dest, &adr[outer], len) != dest + || memcmp (dest, &adr[outer], + MIN (inner - outer, len)) != 0 + || (inner - outer < len + && strlen (dest) != (inner - outer))) + { + printf ("strncpy flunked for outer = %d, inner = %d, len = %Zd\n", + outer, inner, len); + result = 1; + } + } + + adr[inner] = 'T'; + } + } + /* stpcpy test */ for (outer = size - 1; outer >= MAX (0, size - 128); --outer) { |