1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00
2000-08-29  Bruno Haible  <haible@clisp.cons.org>

	* stdio-common/vfscanf.c (_IO_vfscanf): Back out last ungetc change.
	When comparing a char with an int, always cast the char to
	'unsigned char'. New macro ungetc_not_eof, to avoid warnings when
	compiling with -funsigned-char.	Use UCHAR_MAX+1 instead of UCHAR_MAX.
This commit is contained in:
Ulrich Drepper
2000-08-30 20:06:01 +00:00
parent e668889af2
commit 44f8759bc5
2 changed files with 53 additions and 41 deletions

View File

@ -1,3 +1,10 @@
2000-08-29 Bruno Haible <haible@clisp.cons.org>
* stdio-common/vfscanf.c (_IO_vfscanf): Back out last ungetc change.
When comparing a char with an int, always cast the char to
'unsigned char'. New macro ungetc_not_eof, to avoid warnings when
compiling with -funsigned-char. Use UCHAR_MAX+1 instead of UCHAR_MAX.
2000-08-30 Ulrich Drepper <drepper@redhat.com> 2000-08-30 Ulrich Drepper <drepper@redhat.com>
* time/strftime.c (my_strftime): Add compatibility code for use * time/strftime.c (my_strftime): Add compatibility code for use

View File

@ -76,6 +76,8 @@
# define ungetc(c, s) ((void) (c == WEOF \ # define ungetc(c, s) ((void) (c == WEOF \
|| (--read_in, \ || (--read_in, \
_IO_sputbackwc (s, c)))) _IO_sputbackwc (s, c))))
# define ungetc_not_eof(c, s) ((void) (--read_in, \
_IO_sputbackwc (s, c)))
# define inchar() (c == WEOF ? WEOF \ # define inchar() (c == WEOF ? WEOF \
: ((c = _IO_getwc_unlocked (s)), \ : ((c = _IO_getwc_unlocked (s)), \
(void) (c != WEOF && ++read_in), c)) (void) (c != WEOF && ++read_in), c))
@ -102,9 +104,11 @@
# undef EOF # undef EOF
# define EOF WEOF # define EOF WEOF
# else # else
# define ungetc(c, s) ((void) ((int) (signed char) c == EOF \ # define ungetc(c, s) ((void) ((int) c == EOF \
|| (--read_in, \ || (--read_in, \
_IO_sputbackc (s, (unsigned char) c)))) _IO_sputbackc (s, (unsigned char) c))))
# define ungetc_not_eof(c, s) ((void) (--read_in, \
_IO_sputbackc (s, (unsigned char) c)))
# define inchar() (c == EOF ? EOF \ # define inchar() (c == EOF ? EOF \
: ((c = _IO_getc_unlocked (s)), \ : ((c = _IO_getc_unlocked (s)), \
(void) (c != EOF && ++read_in), c)) (void) (c != EOF && ++read_in), c))
@ -170,6 +174,7 @@
__libc_cleanup_region_end (0) __libc_cleanup_region_end (0)
#else #else
# define ungetc(c, s) ((void) (c != EOF && --read_in), ungetc (c, s)) # define ungetc(c, s) ((void) (c != EOF && --read_in), ungetc (c, s))
# define ungetc_not_eof(c, s) (--read_in, (ungetc) (c, s))
# define inchar() (c == EOF ? EOF \ # define inchar() (c == EOF ? EOF \
: ((c = getc (s)), (void) (c != EOF && ++read_in), c)) : ((c = getc (s)), (void) (c != EOF && ++read_in), c))
# define MEMCPY(d, s, n) memcpy (d, s, n) # define MEMCPY(d, s, n) memcpy (d, s, n)
@ -320,7 +325,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
if (wpsize == wpmax) \ if (wpsize == wpmax) \
{ \ { \
CHAR_T *old = wp; \ CHAR_T *old = wp; \
wpmax = UCHAR_MAX > 2 * wpmax ? UCHAR_MAX : 2 * wpmax; \ wpmax = (UCHAR_MAX + 1 > 2 * wpmax ? UCHAR_MAX + 1 : 2 * wpmax); \
wp = (CHAR_T *) alloca (wpmax * sizeof (wchar_t)); \ wp = (CHAR_T *) alloca (wpmax * sizeof (wchar_t)); \
if (old != NULL) \ if (old != NULL) \
MEMCPY (wp, old, wpsize); \ MEMCPY (wp, old, wpsize); \
@ -403,7 +408,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
#endif #endif
#ifndef COMPILE_WSCANF #ifndef COMPILE_WSCANF
if (!isascii (*f)) if (!isascii ((unsigned char) *f))
{ {
/* Non-ASCII, may be a multibyte. */ /* Non-ASCII, may be a multibyte. */
int len = __mbrlen (f, strlen (f), &state); int len = __mbrlen (f, strlen (f), &state);
@ -414,9 +419,9 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
c = inchar (); c = inchar ();
if (c == EOF) if (c == EOF)
input_error (); input_error ();
else if (c != *f++) else if (c != (unsigned char) *f++)
{ {
ungetc (c, s); ungetc_not_eof (c, s);
conv_error (); conv_error ();
} }
} }
@ -475,11 +480,11 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
wpsize = 0; wpsize = 0;
/* Check for a positional parameter specification. */ /* Check for a positional parameter specification. */
if (ISDIGIT (*f)) if (ISDIGIT ((UCHAR_T) *f))
{ {
argpos = *f++ - L_('0'); argpos = (UCHAR_T) *f++ - L_('0');
while (ISDIGIT (*f)) while (ISDIGIT ((UCHAR_T) *f))
argpos = argpos * 10 + (*f++ - L_('0')); argpos = argpos * 10 + ((UCHAR_T) *f++ - L_('0'));
if (*f == L_('$')) if (*f == L_('$'))
++f; ++f;
else else
@ -509,15 +514,15 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
} }
/* We have seen width. */ /* We have seen width. */
if (ISDIGIT (*f)) if (ISDIGIT ((UCHAR_T) *f))
flags |= WIDTH; flags |= WIDTH;
/* Find the maximum field width. */ /* Find the maximum field width. */
width = 0; width = 0;
while (ISDIGIT (*f)) while (ISDIGIT ((UCHAR_T) *f))
{ {
width *= 10; width *= 10;
width += *f++ - L_('0'); width += (UCHAR_T) *f++ - L_('0');
} }
got_width: got_width:
if (width == 0) if (width == 0)
@ -617,7 +622,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
input_error (); input_error ();
if (c != fc) if (c != fc)
{ {
ungetc (c, s); ungetc_not_eof (c, s);
conv_error (); conv_error ();
} }
break; break;
@ -837,7 +842,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
{ {
if (ISSPACE (c)) if (ISSPACE (c))
{ {
ungetc (c, s); ungetc_not_eof (c, s);
break; break;
} }
@ -937,7 +942,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
if (!(flags & SUPPRESS)) if (!(flags & SUPPRESS))
{ {
#ifdef COMPILE_WSCANF #ifdef COMPILE_WSCANF
/* We have to emit the code to get into the intial /* We have to emit the code to get into the initial
state. */ state. */
char buf[MB_LEN_MAX]; char buf[MB_LEN_MAX];
size_t n = __wcrtomb (buf, L'\0', &state); size_t n = __wcrtomb (buf, L'\0', &state);
@ -1002,7 +1007,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
{ {
if (ISSPACE (c)) if (ISSPACE (c))
{ {
ungetc (c, s); ungetc_not_eof (c, s);
break; break;
} }
@ -1263,7 +1268,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
mbdigits[n] = strchr (mbdigits[n], '\0') + 1; mbdigits[n] = strchr (mbdigits[n], '\0') + 1;
cmpp = mbdigits[n]; cmpp = mbdigits[n];
while (*cmpp == c && avail > 0) while ((unsigned char) *cmpp == c && avail > 0)
{ {
if (*++cmpp == '\0') if (*++cmpp == '\0')
break; break;
@ -1288,8 +1293,8 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
{ {
ungetc (c, s); ungetc (c, s);
while (--cmpp > mbdigits[n]) while (--cmpp > mbdigits[n])
ungetc (*cmpp, s); ungetc_not_eof ((unsigned char) *cmpp, s);
c = *cmpp; c = (unsigned char) *cmpp;
} }
/* Advance the pointer to the next string. */ /* Advance the pointer to the next string. */
@ -1316,7 +1321,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
int avail = width > 0 ? width : INT_MAX; int avail = width > 0 ? width : INT_MAX;
cmpp = mbdigits[n]; cmpp = mbdigits[n];
while (*cmpp == c && avail > 0) while ((unsigned char) *cmpp == c && avail > 0)
{ {
if (*++cmpp == '\0') if (*++cmpp == '\0')
break; break;
@ -1340,8 +1345,8 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
{ {
ungetc (c, s); ungetc (c, s);
while (--cmpp > mbdigits[n]) while (--cmpp > mbdigits[n])
ungetc (*cmpp, s); ungetc_not_eof ((unsigned char) *cmpp, s);
c = *cmpp; c = (unsigned char) *cmpp;
} }
/* Advance the pointer to the next string. */ /* Advance the pointer to the next string. */
@ -1377,7 +1382,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
const char *cmpp = thousands; const char *cmpp = thousands;
int avail = width > 0 ? width : INT_MAX; int avail = width > 0 ? width : INT_MAX;
while (*cmpp == c && avail > 0) while ((unsigned char) *cmpp == c && avail > 0)
{ {
ADDW (c); ADDW (c);
if (*++cmpp == '\0') if (*++cmpp == '\0')
@ -1398,8 +1403,8 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
wpsize -= cmpp - thousands; wpsize -= cmpp - thousands;
ungetc (c, s); ungetc (c, s);
while (--cmpp > thousands) while (--cmpp > thousands)
ungetc (*cmpp, s); ungetc_not_eof ((unsigned char) *cmpp, s);
c = *cmpp; c = (unsigned char) *cmpp;
} }
break; break;
} }
@ -1449,7 +1454,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
const char *cmpp = thousands; const char *cmpp = thousands;
int avail = width > 0 ? width : INT_MAX; int avail = width > 0 ? width : INT_MAX;
while (*cmpp == c && avail > 0) while ((unsigned char) *cmpp == c && avail > 0)
{ {
ADDW (c); ADDW (c);
if (*++cmpp == '\0') if (*++cmpp == '\0')
@ -1470,8 +1475,8 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
wpsize -= cmpp - thousands; wpsize -= cmpp - thousands;
ungetc (c, s); ungetc (c, s);
while (--cmpp > thousands) while (--cmpp > thousands)
ungetc (*cmpp, s); ungetc_not_eof ((unsigned char) *cmpp, s);
c = *cmpp; c = (unsigned char) *cmpp;
} }
break; break;
} }
@ -1611,7 +1616,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
const char *cmpp = decimal; const char *cmpp = decimal;
int avail = width > 0 ? width : INT_MAX; int avail = width > 0 ? width : INT_MAX;
while (*cmpp == c && avail > 0) while ((unsigned char) *cmpp == c && avail > 0)
if (*++cmpp == '\0') if (*++cmpp == '\0')
break; break;
else else
@ -1629,7 +1634,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
ungetc (c, s); ungetc (c, s);
if (cmpp == decimal) if (cmpp == decimal)
break; break;
c = *--cmpp; c = (unsigned char) *--cmpp;
} }
conv_error (); conv_error ();
@ -1779,7 +1784,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
if (! got_dot) if (! got_dot)
{ {
while (*cmpp == c && avail > 0) while ((unsigned char) *cmpp == c && avail > 0)
if (*++cmpp == '\0') if (*++cmpp == '\0')
break; break;
else else
@ -1794,7 +1799,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
{ {
/* Add all the characters. */ /* Add all the characters. */
for (cmpp = decimal; *cmpp != '\0'; ++cmpp) for (cmpp = decimal; *cmpp != '\0'; ++cmpp)
ADDW (*cmpp); ADDW ((unsigned char) *cmpp);
if (width > 0) if (width > 0)
width = avail; width = avail;
got_dot = 1; got_dot = 1;
@ -1815,7 +1820,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
++cmp2p; ++cmp2p;
if (cmp2p == cmpp) if (cmp2p == cmpp)
{ {
while (*cmp2p == c && avail > 0) while ((unsigned char) *cmp2p == c && avail > 0)
if (*++cmp2p == '\0') if (*++cmp2p == '\0')
break; break;
else else
@ -1831,7 +1836,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
{ {
/* Add all the characters. */ /* Add all the characters. */
for (cmpp = thousands; *cmpp != '\0'; ++cmpp) for (cmpp = thousands; *cmpp != '\0'; ++cmpp)
ADDW (*cmpp); ADDW ((unsigned char) *cmpp);
if (width > 0) if (width > 0)
width = avail; width = avail;
} }
@ -1924,12 +1929,12 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
#else #else
/* Fill WP with byte flags indexed by character. /* Fill WP with byte flags indexed by character.
We will use this flag map for matching input characters. */ We will use this flag map for matching input characters. */
if (wpmax < UCHAR_MAX) if (wpmax < UCHAR_MAX + 1)
{ {
wpmax = UCHAR_MAX; wpmax = UCHAR_MAX + 1;
wp = (char *) alloca (wpmax); wp = (char *) alloca (wpmax);
} }
memset (wp, '\0', UCHAR_MAX); memset (wp, '\0', UCHAR_MAX + 1);
fc = *f; fc = *f;
if (fc == ']' || fc == '-') if (fc == ']' || fc == '-')
@ -1947,7 +1952,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
{ {
/* Add all characters from the one before the '-' /* Add all characters from the one before the '-'
up to (but not including) the next format char. */ up to (but not including) the next format char. */
for (fc = f[-2]; fc < *f; ++fc) for (fc = (unsigned char) f[-2]; fc < (unsigned char) *f; ++fc)
wp[fc] = 1; wp[fc] = 1;
} }
else else
@ -2069,7 +2074,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
if (wp[c] == not_in) if (wp[c] == not_in)
{ {
ungetc (c, s); ungetc_not_eof (c, s);
break; break;
} }
@ -2270,7 +2275,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
if (wp[c] == not_in) if (wp[c] == not_in)
{ {
ungetc (c, s); ungetc_not_eof (c, s);
break; break;
} }
@ -2323,7 +2328,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
if (!(flags & SUPPRESS)) if (!(flags & SUPPRESS))
{ {
#ifdef COMPILE_WSCANF #ifdef COMPILE_WSCANF
/* We have to emit the code to get into the intial /* We have to emit the code to get into the initial
state. */ state. */
char buf[MB_LEN_MAX]; char buf[MB_LEN_MAX];
size_t n = __wcrtomb (buf, L'\0', &state); size_t n = __wcrtomb (buf, L'\0', &state);