mirror of git://sourceware.org/git/glibc.git
[BZ #4963]
* wcsmbs/wcsnlen.c: Don't reference before checking the length. * string/stratcliff.c: Make usable to test wide char functions. * wcsmbs/wcsatcliff.c: New file. * wcsmbs/Makefiel (tests): Add wcsatcliff.
This commit is contained in:
parent
27f3d4467d
commit
9cc198f65b
|
|
@ -1,5 +1,11 @@
|
||||||
2007-09-23 Ulrich Drepper <drepper@redhat.com>
|
2007-09-23 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
[BZ #4963]
|
||||||
|
* wcsmbs/wcsnlen.c: Don't reference before checking the length.
|
||||||
|
* string/stratcliff.c: Make usable to test wide char functions.
|
||||||
|
* wcsmbs/wcsatcliff.c: New file.
|
||||||
|
* wcsmbs/Makefiel (tests): Add wcsatcliff.
|
||||||
|
|
||||||
[BZ #4972]
|
[BZ #4972]
|
||||||
* iconvdata/Makefile (modules): Add MAC-CENTRALEUROPE.
|
* iconvdata/Makefile (modules): Add MAC-CENTRALEUROPE.
|
||||||
(distribute): Add mac-centraleurope.c.
|
(distribute): Add mac-centraleurope.c.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/* Test for string function add boundaries of usable memory.
|
/* Test for string function add boundaries of usable memory.
|
||||||
Copyright (C) 1996,1997,1999-2002,2003 Free Software Foundation, Inc.
|
Copyright (C) 1996,1997,1999-2002,2003,2007 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||||
|
|
||||||
|
|
@ -31,20 +31,40 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
#ifndef MAX
|
#ifndef CHAR
|
||||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
# define L(c) c
|
||||||
|
# define CHAR char
|
||||||
|
# define MEMSET memset
|
||||||
|
# define STRLEN strlen
|
||||||
|
# define STRNLEN strnlen
|
||||||
|
# define STRCHR strchr
|
||||||
|
# define STRRCHR strrchr
|
||||||
|
# define STRCPY strcpy
|
||||||
|
# define STRNCPY strncpy
|
||||||
|
# define MEMCMP memcmp
|
||||||
|
# define STPCPY stpcpy
|
||||||
|
# define STPNCPY stpncpy
|
||||||
|
# define MEMCPY memcpy
|
||||||
|
# define MEMPCPY mempcpy
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, char *argv[])
|
#define STRINGIFY(s) STRINGIFY2 (s)
|
||||||
|
#define STRINGIFY2(s) #s
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_test (void)
|
||||||
{
|
{
|
||||||
int size = sysconf (_SC_PAGESIZE);
|
int size = sysconf (_SC_PAGESIZE);
|
||||||
char *adr, *dest;
|
int nchars = size / sizeof (CHAR);
|
||||||
|
CHAR *adr;
|
||||||
|
CHAR *dest;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
adr = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE,
|
adr = (CHAR *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE,
|
||||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||||
dest = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE,
|
dest = (CHAR *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE,
|
||||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||||
if (adr == MAP_FAILED || dest == MAP_FAILED)
|
if (adr == MAP_FAILED || dest == MAP_FAILED)
|
||||||
{
|
{
|
||||||
|
|
@ -60,270 +80,310 @@ main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int inner, middle, outer;
|
int inner, middle, outer;
|
||||||
|
|
||||||
mprotect(adr, size, PROT_NONE);
|
mprotect (adr, size, PROT_NONE);
|
||||||
mprotect(adr + 2 * size, size, PROT_NONE);
|
mprotect (adr + 2 * nchars, size, PROT_NONE);
|
||||||
adr += size;
|
adr += nchars;
|
||||||
|
|
||||||
mprotect(dest, size, PROT_NONE);
|
mprotect (dest, size, PROT_NONE);
|
||||||
mprotect(dest + 2 * size, size, PROT_NONE);
|
mprotect (dest + 2 * nchars, size, PROT_NONE);
|
||||||
dest += size;
|
dest += nchars;
|
||||||
|
|
||||||
memset (adr, 'T', size);
|
MEMSET (adr, L('T'), nchars);
|
||||||
|
|
||||||
/* strlen test */
|
/* strlen/wcslen test */
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
{
|
{
|
||||||
for (inner = MAX (outer, size - 64); inner < size; ++inner)
|
for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
|
||||||
{
|
{
|
||||||
adr[inner] = '\0';
|
adr[inner] = L('\0');
|
||||||
|
|
||||||
if (strlen (&adr[outer]) != (size_t) (inner - outer))
|
if (STRLEN (&adr[outer]) != (size_t) (inner - outer))
|
||||||
{
|
{
|
||||||
printf ("strlen flunked for outer = %d, inner = %d\n",
|
printf ("%s flunked for outer = %d, inner = %d\n",
|
||||||
outer, inner);
|
STRINGIFY (STRLEN), outer, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
adr[inner] = 'T';
|
adr[inner] = L('T');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* strchr test */
|
/* strnlen/wcsnlen test */
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars; outer >= MAX (0, nchars - 128); --outer)
|
||||||
{
|
{
|
||||||
for (middle = MAX (outer, size - 64); middle < size; ++middle)
|
for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
|
||||||
{
|
{
|
||||||
for (inner = middle; inner < size; ++inner)
|
adr[inner] = L('\0');
|
||||||
{
|
|
||||||
char *cp;
|
|
||||||
adr[middle] = 'V';
|
|
||||||
adr[inner] = '\0';
|
|
||||||
|
|
||||||
cp = strchr (&adr[outer], 'V');
|
if (STRNLEN (&adr[outer], inner - outer + 1)
|
||||||
|
!= (size_t) (inner - outer))
|
||||||
|
{
|
||||||
|
printf ("%s flunked for outer = %d, inner = %d\n",
|
||||||
|
STRINGIFY (STRNLEN), outer, inner);
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
adr[inner] = L('T');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (outer = nchars; outer >= MAX (0, nchars - 128); --outer)
|
||||||
|
{
|
||||||
|
for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
|
||||||
|
{
|
||||||
|
if (STRNLEN (&adr[outer], inner - outer + 1)
|
||||||
|
!= (size_t) (inner - outer + 1))
|
||||||
|
{
|
||||||
|
printf ("%s flunked bounded for outer = %d, inner = %d\n",
|
||||||
|
STRINGIFY (STRNLEN), outer, inner);
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* strchr/wcschr test */
|
||||||
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
|
{
|
||||||
|
for (middle = MAX (outer, nchars - 64); middle < nchars; ++middle)
|
||||||
|
{
|
||||||
|
for (inner = middle; inner < nchars; ++inner)
|
||||||
|
{
|
||||||
|
adr[middle] = L('V');
|
||||||
|
adr[inner] = L('\0');
|
||||||
|
|
||||||
|
CHAR *cp = STRCHR (&adr[outer], L('V'));
|
||||||
|
|
||||||
if ((inner == middle && cp != NULL)
|
if ((inner == middle && cp != NULL)
|
||||||
|| (inner != middle
|
|| (inner != middle
|
||||||
&& (cp - &adr[outer]) != middle - outer))
|
&& (cp - &adr[outer]) != middle - outer))
|
||||||
{
|
{
|
||||||
printf ("strchr flunked for outer = %d, middle = %d, "
|
printf ("%s flunked for outer = %d, middle = %d, "
|
||||||
"inner = %d\n", outer, middle, inner);
|
"inner = %d\n",
|
||||||
|
STRINGIFY (STRCHR), outer, middle, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
adr[inner] = 'T';
|
adr[inner] = L('T');
|
||||||
adr[middle] = 'T';
|
adr[middle] = L('T');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Special test. */
|
/* Special test. */
|
||||||
adr[size - 1] = '\0';
|
adr[nchars - 1] = L('\0');
|
||||||
if (strchr (&adr[size - 1], '\n') != NULL)
|
if (STRCHR (&adr[nchars - 1], L('\n')) != NULL)
|
||||||
{
|
{
|
||||||
puts ("strchr flunked for test of empty string at end of page");
|
printf ("%s flunked test of empty string at end of page\n",
|
||||||
|
STRINGIFY (STRCHR));
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* strrchr test */
|
/* strrchr/wcsrchr test */
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
{
|
{
|
||||||
for (middle = MAX (outer, size - 64); middle < size; ++middle)
|
for (middle = MAX (outer, nchars - 64); middle < nchars; ++middle)
|
||||||
{
|
{
|
||||||
for (inner = middle; inner < size; ++inner)
|
for (inner = middle; inner < nchars; ++inner)
|
||||||
{
|
{
|
||||||
char *cp;
|
adr[middle] = L('V');
|
||||||
adr[middle] = 'V';
|
adr[inner] = L('\0');
|
||||||
adr[inner] = '\0';
|
|
||||||
|
|
||||||
cp = strrchr (&adr[outer], 'V');
|
CHAR *cp = STRRCHR (&adr[outer], L('V'));
|
||||||
|
|
||||||
if ((inner == middle && cp != NULL)
|
if ((inner == middle && cp != NULL)
|
||||||
|| (inner != middle
|
|| (inner != middle
|
||||||
&& (cp - &adr[outer]) != middle - outer))
|
&& (cp - &adr[outer]) != middle - outer))
|
||||||
{
|
{
|
||||||
printf ("strrchr flunked for outer = %d, middle = %d, "
|
printf ("%s flunked for outer = %d, middle = %d, "
|
||||||
"inner = %d\n", outer, middle, inner);
|
"inner = %d\n",
|
||||||
|
STRINGIFY (STRRCHR), outer, middle, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
adr[inner] = 'T';
|
adr[inner] = L('T');
|
||||||
adr[middle] = 'T';
|
adr[middle] = L('T');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This function only exists for single-byte characters. */
|
||||||
|
#ifndef WCSTEST
|
||||||
/* rawmemchr test */
|
/* rawmemchr test */
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
{
|
{
|
||||||
for (middle = MAX (outer, size - 64); middle < size; ++middle)
|
for (middle = MAX (outer, nchars - 64); middle < nchars; ++middle)
|
||||||
{
|
{
|
||||||
char *cp;
|
adr[middle] = L('V');
|
||||||
adr[middle] = 'V';
|
|
||||||
|
|
||||||
cp = rawmemchr (&adr[outer], 'V');
|
CHAR *cp = rawmemchr (&adr[outer], L('V'));
|
||||||
|
|
||||||
if (cp - &adr[outer] != middle - outer)
|
if (cp - &adr[outer] != middle - outer)
|
||||||
{
|
{
|
||||||
printf ("rawmemchr flunked for outer = %d, middle = %d\n",
|
printf ("%s flunked for outer = %d, middle = %d\n",
|
||||||
outer, middle);
|
STRINGIFY (rawmemchr), outer, middle);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
adr[middle] = 'T';
|
adr[middle] = L('T');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* strcpy test */
|
/* strcpy/wcscpy test */
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
{
|
{
|
||||||
for (inner = MAX (outer, size - 64); inner < size; ++inner)
|
for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
|
||||||
{
|
{
|
||||||
adr[inner] = '\0';
|
adr[inner] = L('\0');
|
||||||
|
|
||||||
if (strcpy (dest, &adr[outer]) != dest
|
if (STRCPY (dest, &adr[outer]) != dest
|
||||||
|| strlen (dest) != (size_t) (inner - outer))
|
|| STRLEN (dest) != (size_t) (inner - outer))
|
||||||
{
|
{
|
||||||
printf ("strcpy flunked for outer = %d, inner = %d\n",
|
printf ("%s flunked for outer = %d, inner = %d\n",
|
||||||
outer, inner);
|
STRINGIFY (STRCPY), outer, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
adr[inner] = 'T';
|
adr[inner] = L('T');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* strncpy tests */
|
/* strncpy tests */
|
||||||
adr[size-1] = 'T';
|
adr[nchars - 1] = L('T');
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
for (len = 0; len < size - outer; ++len)
|
for (len = 0; len < nchars - outer; ++len)
|
||||||
{
|
{
|
||||||
if (strncpy (dest, &adr[outer], len) != dest
|
if (STRNCPY (dest, &adr[outer], len) != dest
|
||||||
|| memcmp (dest, &adr[outer], len) != 0)
|
|| MEMCMP (dest, &adr[outer], len) != 0)
|
||||||
{
|
{
|
||||||
printf ("outer strncpy flunked for outer = %d, len = %Zd\n",
|
printf ("outer %s flunked for outer = %d, len = %Zd\n",
|
||||||
outer, len);
|
STRINGIFY (STRNCPY), outer, len);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
adr[size-1] = '\0';
|
adr[nchars - 1] = L('\0');
|
||||||
|
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
{
|
{
|
||||||
for (inner = MAX (outer, size - 64); inner < size; ++inner)
|
for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
adr[inner] = '\0';
|
adr[inner] = L('\0');
|
||||||
|
|
||||||
for (len = 0; len < size - outer + 64; ++len)
|
for (len = 0; len < nchars - outer + 64; ++len)
|
||||||
{
|
{
|
||||||
if (strncpy (dest, &adr[outer], len) != dest
|
if (STRNCPY (dest, &adr[outer], len) != dest
|
||||||
|| memcmp (dest, &adr[outer],
|
|| MEMCMP (dest, &adr[outer],
|
||||||
MIN (inner - outer, len)) != 0
|
MIN (inner - outer, len)) != 0
|
||||||
|| (inner - outer < len
|
|| (inner - outer < len
|
||||||
&& strlen (dest) != (inner - outer)))
|
&& STRLEN (dest) != (inner - outer)))
|
||||||
{
|
{
|
||||||
printf ("strncpy flunked for outer = %d, inner = %d, len = %Zd\n",
|
printf ("%s flunked for outer = %d, inner = %d, "
|
||||||
outer, inner, len);
|
"len = %Zd\n",
|
||||||
|
STRINGIFY (STRNCPY), outer, inner, len);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
if (strncpy (dest + 1, &adr[outer], len) != dest + 1
|
if (STRNCPY (dest + 1, &adr[outer], len) != dest + 1
|
||||||
|| memcmp (dest + 1, &adr[outer],
|
|| MEMCMP (dest + 1, &adr[outer],
|
||||||
MIN (inner - outer, len)) != 0
|
MIN (inner - outer, len)) != 0
|
||||||
|| (inner - outer < len
|
|| (inner - outer < len
|
||||||
&& strlen (dest + 1) != (inner - outer)))
|
&& STRLEN (dest + 1) != (inner - outer)))
|
||||||
{
|
{
|
||||||
printf ("strncpy+1 flunked for outer = %d, inner = %d, len = %Zd\n",
|
printf ("%s+1 flunked for outer = %d, inner = %d, "
|
||||||
outer, inner, len);
|
"len = %Zd\n",
|
||||||
|
STRINGIFY (STRNCPY), outer, inner, len);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
adr[inner] = 'T';
|
adr[inner] = L('T');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stpcpy test */
|
/* stpcpy/wcpcpy test */
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
{
|
{
|
||||||
for (inner = MAX (outer, size - 64); inner < size; ++inner)
|
for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
|
||||||
{
|
{
|
||||||
adr[inner] = '\0';
|
adr[inner] = L('\0');
|
||||||
|
|
||||||
if ((stpcpy (dest, &adr[outer]) - dest) != inner - outer)
|
if ((STPCPY (dest, &adr[outer]) - dest) != inner - outer)
|
||||||
{
|
{
|
||||||
printf ("stpcpy flunked for outer = %d, inner = %d\n",
|
printf ("%s flunked for outer = %d, inner = %d\n",
|
||||||
outer, inner);
|
STRINGIFY (STPCPY), outer, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
adr[inner] = 'T';
|
adr[inner] = L('T');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stpncpy test */
|
/* stpncpy/wcpncpy test */
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
{
|
{
|
||||||
for (middle = MAX (outer, size - 64); middle < size; ++middle)
|
for (middle = MAX (outer, nchars - 64); middle < nchars; ++middle)
|
||||||
{
|
{
|
||||||
adr[middle] = '\0';
|
adr[middle] = L('\0');
|
||||||
|
|
||||||
for (inner = 0; inner < size - outer; ++ inner)
|
for (inner = 0; inner < nchars - outer; ++ inner)
|
||||||
{
|
{
|
||||||
if ((stpncpy (dest, &adr[outer], inner) - dest)
|
if ((STPNCPY (dest, &adr[outer], inner) - dest)
|
||||||
!= MIN (inner, middle - outer))
|
!= MIN (inner, middle - outer))
|
||||||
{
|
{
|
||||||
printf ("stpncpy flunked for outer = %d, middle = %d, "
|
printf ("%s flunked for outer = %d, middle = %d, "
|
||||||
"inner = %d\n", outer, middle, inner);
|
"inner = %d\n",
|
||||||
|
STRINGIFY (STPNCPY), outer, middle, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
adr[middle] = 'T';
|
adr[middle] = L('T');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* memcpy test */
|
/* memcpy/wmemcpy test */
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
for (inner = 0; inner < size - outer; ++inner)
|
for (inner = 0; inner < nchars - outer; ++inner)
|
||||||
if (memcpy (dest, &adr[outer], inner) != dest)
|
if (MEMCPY (dest, &adr[outer], inner) != dest)
|
||||||
{
|
{
|
||||||
printf ("memcpy flunked for outer = %d, inner = %d\n",
|
printf ("%s flunked for outer = %d, inner = %d\n",
|
||||||
outer, inner);
|
STRINGIFY (MEMCPY), outer, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mempcpy test */
|
/* mempcpy/wmempcpy test */
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
for (inner = 0; inner < size - outer; ++inner)
|
for (inner = 0; inner < nchars - outer; ++inner)
|
||||||
if (mempcpy (dest, &adr[outer], inner) != dest + inner)
|
if (MEMPCPY (dest, &adr[outer], inner) != dest + inner)
|
||||||
{
|
{
|
||||||
printf ("mempcpy flunked for outer = %d, inner = %d\n",
|
printf ("%s flunked for outer = %d, inner = %d\n",
|
||||||
outer, inner);
|
STRINGIFY (MEMPCPY), outer, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This function only exists for single-byte characters. */
|
||||||
|
#ifndef WCSTEST
|
||||||
/* memccpy test */
|
/* memccpy test */
|
||||||
memset (adr, '\0', size);
|
memset (adr, '\0', nchars);
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
for (inner = 0; inner < size - outer; ++inner)
|
for (inner = 0; inner < nchars - outer; ++inner)
|
||||||
if (memccpy (dest, &adr[outer], '\1', inner) != NULL)
|
if (memccpy (dest, &adr[outer], L('\1'), inner) != NULL)
|
||||||
{
|
{
|
||||||
printf ("memccpy flunked full copy for outer = %d, inner = %d\n",
|
printf ("memccpy flunked full copy for outer = %d, inner = %d\n",
|
||||||
outer, inner);
|
outer, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
|
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
|
||||||
for (middle = 0; middle < size - outer; ++middle)
|
for (middle = 0; middle < nchars - outer; ++middle)
|
||||||
{
|
{
|
||||||
memset (dest, '\2', middle + 1);
|
memset (dest, L('\2'), middle + 1);
|
||||||
for (inner = 0; inner < middle; ++inner)
|
for (inner = 0; inner < middle; ++inner)
|
||||||
{
|
{
|
||||||
adr[outer + inner] = '\1';
|
adr[outer + inner] = L('\1');
|
||||||
|
|
||||||
if (memccpy (dest, &adr[outer], '\1', middle + 128)
|
if (memccpy (dest, &adr[outer], '\1', middle + 128)
|
||||||
!= dest + inner + 1)
|
!= dest + inner + 1)
|
||||||
|
|
@ -333,17 +393,21 @@ memccpy flunked partial copy for outer = %d, middle = %d, inner = %d\n",
|
||||||
outer, middle, inner);
|
outer, middle, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
else if (dest[inner + 1] != '\2')
|
else if (dest[inner + 1] != L('\2'))
|
||||||
{
|
{
|
||||||
printf ("\
|
printf ("\
|
||||||
memccpy copied too much for outer = %d, middle = %d, inner = %d\n",
|
memccpy copied too much for outer = %d, middle = %d, inner = %d\n",
|
||||||
outer, middle, inner);
|
outer, middle, inner);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
adr[outer + inner] = '\0';
|
adr[outer + inner] = L('\0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define TEST_FUNCTION do_test ()
|
||||||
|
#include "../test-skeleton.c"
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,8 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
|
||||||
isoc99_swscanf isoc99_vswscanf
|
isoc99_swscanf isoc99_vswscanf
|
||||||
|
|
||||||
tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
|
tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
|
||||||
tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2
|
tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \
|
||||||
|
wcsatcliff
|
||||||
|
|
||||||
include ../Rules
|
include ../Rules
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
#define WCSTEST 1
|
||||||
|
#define L(c) L##c
|
||||||
|
#define CHAR wchar_t
|
||||||
|
#define MEMSET wmemset
|
||||||
|
#define STRLEN wcslen
|
||||||
|
#define STRNLEN wcsnlen
|
||||||
|
#define STRCHR wcschr
|
||||||
|
#define STRRCHR wcsrchr
|
||||||
|
#define STRCPY wcscpy
|
||||||
|
#define STRNCPY wcsncpy
|
||||||
|
#define MEMCMP wmemcmp
|
||||||
|
#define STPCPY wcpcpy
|
||||||
|
#define STPNCPY wcpncpy
|
||||||
|
#define MEMCPY wmemcpy
|
||||||
|
#define MEMPCPY wmempcpy
|
||||||
|
|
||||||
|
|
||||||
|
#include "../string/stratcliff.c"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
|
/* Copyright (C) 1998, 1999, 2007 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
||||||
|
|
||||||
|
|
@ -28,13 +28,16 @@ __wcsnlen (s, maxlen)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
while (s[len] != L'\0' && maxlen > 0)
|
while (maxlen > 0 && s[len] != L'\0')
|
||||||
{
|
{
|
||||||
if (s[++len] == L'\0' || --maxlen == 0)
|
++len;
|
||||||
|
if (--maxlen == 0 || s[len] == L'\0')
|
||||||
return len;
|
return len;
|
||||||
if (s[++len] == L'\0' || --maxlen == 0)
|
++len;
|
||||||
|
if (--maxlen == 0 || s[len] == L'\0')
|
||||||
return len;
|
return len;
|
||||||
if (s[++len] == L'\0' || --maxlen == 0)
|
++len;
|
||||||
|
if (--maxlen == 0 || s[len] == L'\0')
|
||||||
return len;
|
return len;
|
||||||
++len;
|
++len;
|
||||||
--maxlen;
|
--maxlen;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue