mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-14 01:00:07 +00:00
f9a906e786
sizeof (wchar_t) rather than multiplying __len by sizeof (wchar_t). Pass __bos (__dst) / sizeof (wchar_t) to the *_chk routine. * wcsmbs/bits/wchar2.h (mbsrtowcs, mbsnrtowcs): Likewise. * debug/mbsnrtowcs_chk.c (__mbsnrtowcs_chk): Don't multiply len by sizeof (wchar_t). * debug/mbsrtowcs_chk.c (__mbsrtowcs_chk): Likewise. * debug/mbstowcs_chk.c (__mbstowcs_chk): Likewise. Fix type of SRC argument. Pass &SRC rather than SRC to __mbsrtowcs. * debug/wcstombs_chk.c (__wcstombs_chk): Pass &SRC rather than SRC to __wcsrtombs. * debug/tst-chk1.c: Include assert.h. (do_test): Change enough array from VLA into a fixed size array. Assert that MB_CUR_MAX is <= sizeof (enough). Use FAIL () macro instead of print error details. Add several new tests. Kill some unused variable warnings.
36 lines
1.2 KiB
C
36 lines
1.2 KiB
C
/* Copyright (C) 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
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, write to the Free
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307 USA. */
|
|
|
|
#include <locale.h>
|
|
#include <string.h>
|
|
#include <wchar.h>
|
|
|
|
|
|
size_t
|
|
__mbstowcs_chk (wchar_t *dst, const char *src, size_t len, size_t dstlen)
|
|
{
|
|
if (__builtin_expect (dstlen < len, 0))
|
|
__chk_fail ();
|
|
|
|
mbstate_t state;
|
|
|
|
memset (&state, '\0', sizeof state);
|
|
/* Return how many we wrote (or maybe an error). */
|
|
return __mbsrtowcs (dst, &src, len, &state);
|
|
}
|