Pass NULL instead of a pointer to a zeroed mbstate_t object.
This commit is contained in:
parent
22749a6e2a
commit
2a49d3767f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=122105
@ -345,18 +345,16 @@ __wcsconv(wchar_t *wcsarg, int prec)
|
||||
wchar_t *p;
|
||||
char *convbuf, *mbp;
|
||||
size_t clen, nbytes;
|
||||
mbstate_t mbs;
|
||||
|
||||
/*
|
||||
* Determine the number of bytes to output and allocate space for
|
||||
* the output.
|
||||
*/
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
if (prec >= 0) {
|
||||
nbytes = 0;
|
||||
p = wcsarg;
|
||||
for (;;) {
|
||||
clen = wcrtomb(buf, *p++, &mbs);
|
||||
clen = wcrtomb(buf, *p++, NULL);
|
||||
if (clen == 0 || clen == (size_t)-1 ||
|
||||
nbytes + clen > prec)
|
||||
break;
|
||||
@ -364,7 +362,7 @@ __wcsconv(wchar_t *wcsarg, int prec)
|
||||
}
|
||||
} else {
|
||||
p = wcsarg;
|
||||
nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, &mbs);
|
||||
nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, NULL);
|
||||
if (nbytes == (size_t)-1)
|
||||
return (NULL);
|
||||
}
|
||||
@ -377,9 +375,8 @@ __wcsconv(wchar_t *wcsarg, int prec)
|
||||
*/
|
||||
mbp = convbuf;
|
||||
p = wcsarg;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
while (mbp - convbuf < nbytes) {
|
||||
clen = wcrtomb(mbp, *p++, &mbs);
|
||||
clen = wcrtomb(mbp, *p++, NULL);
|
||||
if (clen == 0 || clen == (size_t)-1)
|
||||
break;
|
||||
mbp += clen;
|
||||
@ -795,12 +792,10 @@ reswitch: switch (ch) {
|
||||
/*FALLTHROUGH*/
|
||||
case 'c':
|
||||
if (flags & LONGINT) {
|
||||
mbstate_t mbs;
|
||||
size_t mbseqlen;
|
||||
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
mbseqlen = wcrtomb(cp = buf,
|
||||
(wchar_t)GETARG(wint_t), &mbs);
|
||||
(wchar_t)GETARG(wint_t), NULL);
|
||||
if (mbseqlen == (size_t)-1) {
|
||||
fp->_flags |= __SERR;
|
||||
goto error;
|
||||
|
@ -140,7 +140,6 @@ __svfscanf(FILE *fp, const char *fmt0, va_list ap)
|
||||
char buf[BUF]; /* buffer for numeric and mb conversions */
|
||||
wchar_t *wcp; /* handy wide character pointer */
|
||||
wchar_t *wcp0; /* saves original value of wcp */
|
||||
mbstate_t mbs; /* multibyte conversion state */
|
||||
size_t nconv; /* length of multibyte sequence converted */
|
||||
|
||||
/* `basefix' is used to avoid `if' tests in the integer scanner */
|
||||
@ -367,8 +366,7 @@ again: c = *fmt++;
|
||||
buf[n++] = *fp->_p;
|
||||
fp->_p++;
|
||||
fp->_r--;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
nconv = mbrtowc(wcp, buf, n, &mbs);
|
||||
nconv = mbrtowc(wcp, buf, n, NULL);
|
||||
if (nconv == (size_t)-1) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
@ -447,8 +445,7 @@ again: c = *fmt++;
|
||||
buf[n++] = *fp->_p;
|
||||
fp->_p++;
|
||||
fp->_r--;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
nconv = mbrtowc(wcp, buf, n, &mbs);
|
||||
nconv = mbrtowc(wcp, buf, n, NULL);
|
||||
if (nconv == (size_t)-1) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
@ -548,8 +545,7 @@ again: c = *fmt++;
|
||||
buf[n++] = *fp->_p;
|
||||
fp->_p++;
|
||||
fp->_r--;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
nconv = mbrtowc(wcp, buf, n, &mbs);
|
||||
nconv = mbrtowc(wcp, buf, n, NULL);
|
||||
if (nconv == (size_t)-1) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
|
@ -328,7 +328,6 @@ __mbsconv(char *mbsarg, int prec)
|
||||
wchar_t *convbuf, *wcp;
|
||||
const char *p;
|
||||
size_t insize, nchars, nconv;
|
||||
mbstate_t mbs;
|
||||
|
||||
if (mbsarg == NULL)
|
||||
return (NULL);
|
||||
@ -342,11 +341,10 @@ __mbsconv(char *mbsarg, int prec)
|
||||
* String is not guaranteed to be NUL-terminated. Find the
|
||||
* number of characters to print.
|
||||
*/
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
p = mbsarg;
|
||||
insize = nchars = 0;
|
||||
while (nchars != (size_t)prec) {
|
||||
nconv = mbrlen(p, MB_CUR_MAX, &mbs);
|
||||
nconv = mbrlen(p, MB_CUR_MAX, NULL);
|
||||
if (nconv == 0 || nconv == (size_t)-1 ||
|
||||
nconv == (size_t)-2)
|
||||
break;
|
||||
@ -369,9 +367,8 @@ __mbsconv(char *mbsarg, int prec)
|
||||
return (NULL);
|
||||
wcp = convbuf;
|
||||
p = mbsarg;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
while (insize != 0) {
|
||||
nconv = mbrtowc(wcp, p, insize, &mbs);
|
||||
nconv = mbrtowc(wcp, p, insize, NULL);
|
||||
if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2)
|
||||
break;
|
||||
wcp++;
|
||||
|
@ -146,7 +146,6 @@ __vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)
|
||||
wint_t wi; /* handy wint_t */
|
||||
char *mbp; /* multibyte string pointer for %c %s %[ */
|
||||
size_t nconv; /* number of bytes in mb. conversion */
|
||||
mbstate_t mbs; /* multibyte state */
|
||||
char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */
|
||||
|
||||
/* `basefix' is used to avoid `if' tests in the integer scanner */
|
||||
@ -379,17 +378,16 @@ again: c = *fmt++;
|
||||
if (!(flags & SUPPRESS))
|
||||
mbp = va_arg(ap, char *);
|
||||
n = 0;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
while (width != 0 &&
|
||||
(wi = __fgetwc(fp)) != WEOF) {
|
||||
if (width >= MB_CUR_MAX &&
|
||||
!(flags & SUPPRESS)) {
|
||||
nconv = wcrtomb(mbp, wi, &mbs);
|
||||
nconv = wcrtomb(mbp, wi, NULL);
|
||||
if (nconv == (size_t)-1)
|
||||
goto input_failure;
|
||||
} else {
|
||||
nconv = wcrtomb(mbbuf, wi,
|
||||
&mbs);
|
||||
NULL);
|
||||
if (nconv == (size_t)-1)
|
||||
goto input_failure;
|
||||
if (nconv > width) {
|
||||
@ -444,17 +442,16 @@ again: c = *fmt++;
|
||||
if (!(flags & SUPPRESS))
|
||||
mbp = va_arg(ap, char *);
|
||||
n = 0;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
while ((wi = __fgetwc(fp)) != WEOF &&
|
||||
width != 0 && INCCL(wi)) {
|
||||
if (width >= MB_CUR_MAX &&
|
||||
!(flags & SUPPRESS)) {
|
||||
nconv = wcrtomb(mbp, wi, &mbs);
|
||||
nconv = wcrtomb(mbp, wi, NULL);
|
||||
if (nconv == (size_t)-1)
|
||||
goto input_failure;
|
||||
} else {
|
||||
nconv = wcrtomb(mbbuf, wi,
|
||||
&mbs);
|
||||
NULL);
|
||||
if (nconv == (size_t)-1)
|
||||
goto input_failure;
|
||||
if (nconv > width)
|
||||
@ -505,18 +502,17 @@ again: c = *fmt++;
|
||||
} else {
|
||||
if (!(flags & SUPPRESS))
|
||||
mbp = va_arg(ap, char *);
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
while ((wi = __fgetwc(fp)) != WEOF &&
|
||||
width != 0 &&
|
||||
!iswspace(wi)) {
|
||||
if (width >= MB_CUR_MAX &&
|
||||
!(flags & SUPPRESS)) {
|
||||
nconv = wcrtomb(mbp, wi, &mbs);
|
||||
nconv = wcrtomb(mbp, wi, NULL);
|
||||
if (nconv == (size_t)-1)
|
||||
goto input_failure;
|
||||
} else {
|
||||
nconv = wcrtomb(mbbuf, wi,
|
||||
&mbs);
|
||||
NULL);
|
||||
if (nconv == (size_t)-1)
|
||||
goto input_failure;
|
||||
if (nconv > width)
|
||||
|
@ -45,7 +45,6 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
|
||||
{
|
||||
FILE f;
|
||||
struct __sFILEX ext;
|
||||
mbstate_t mbs;
|
||||
char *mbp;
|
||||
int ret, sverrno;
|
||||
|
||||
@ -73,12 +72,11 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
|
||||
}
|
||||
*f._p = '\0';
|
||||
mbp = f._bf._base;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
/*
|
||||
* XXX Undo the conversion from wide characters to multibyte that
|
||||
* fputwc() did in __vfwprintf().
|
||||
*/
|
||||
if (mbsrtowcs(s, (const char **)&mbp, n, &mbs) == (size_t)-1) {
|
||||
if (mbsrtowcs(s, (const char **)&mbp, n, NULL) == (size_t)-1) {
|
||||
free(f._bf._base);
|
||||
errno = EILSEQ;
|
||||
return (-1);
|
||||
|
@ -65,7 +65,6 @@ vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt,
|
||||
va_list ap)
|
||||
{
|
||||
FILE f;
|
||||
mbstate_t mbs;
|
||||
struct __sFILEX ext;
|
||||
char *mbstr;
|
||||
size_t mlen;
|
||||
@ -77,8 +76,7 @@ vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt,
|
||||
*/
|
||||
if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL)
|
||||
return (EOF);
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
if ((mlen = wcsrtombs(mbstr, &str, SIZE_T_MAX, &mbs)) == (size_t)-1) {
|
||||
if ((mlen = wcsrtombs(mbstr, &str, SIZE_T_MAX, NULL)) == (size_t)-1) {
|
||||
free(mbstr);
|
||||
return (EOF);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user