Bugfix: Correctly count the number of characters read for %l[ conversions.

This commit is contained in:
David Schultz 2012-04-22 21:28:14 +00:00
parent 01d2a7858e
commit f010dc7dc4

View File

@ -248,12 +248,12 @@ convert_wccl(FILE *fp, wchar_t *wcp, int width, const char *ccltab)
{ {
mbstate_t mbs; mbstate_t mbs;
wchar_t twc; wchar_t twc;
int n, nchars, nconv, nread; int n, nchars, nconv;
char buf[MB_CUR_MAX]; char buf[MB_CUR_MAX];
if (wcp == SUPPRESS_PTR) if (wcp == SUPPRESS_PTR)
wcp = &twc; wcp = &twc;
n = nread = 0; n = 0;
nchars = 0; nchars = 0;
while (width != 0) { while (width != 0) {
if (n == MB_CUR_MAX) { if (n == MB_CUR_MAX) {
@ -279,7 +279,6 @@ convert_wccl(FILE *fp, wchar_t *wcp, int width, const char *ccltab)
} }
break; break;
} }
nread += n;
width--; width--;
if (wcp != &twc) if (wcp != &twc)
wcp++; wcp++;
@ -298,12 +297,10 @@ convert_wccl(FILE *fp, wchar_t *wcp, int width, const char *ccltab)
fp->_flags |= __SERR; fp->_flags |= __SERR;
return (-1); return (-1);
} }
n = nchars; if (nchars == 0)
if (n == 0)
return (0); return (0);
*wcp = L'\0'; *wcp = L'\0';
/* XXX This matches historical behavior, but it's wrong. */ return (nchars);
return (nread + n);
} }
static __inline int static __inline int