# define ungetc(c, s) ((void) (c == WEOF \
|| (--read_in, \
_IO_sputbackwc (s, c))))
+# define ungetc_not_eof(c, s) ((void) (--read_in, \
+ _IO_sputbackwc (s, c)))
# define inchar() (c == WEOF ? WEOF \
: ((c = _IO_getwc_unlocked (s)), \
(void) (c != WEOF && ++read_in), c))
# undef EOF
# define EOF WEOF
# else
-# define ungetc(c, s) ((void) ((int) (signed char) c == EOF \
+# define ungetc(c, s) ((void) ((int) c == EOF \
|| (--read_in, \
_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 \
: ((c = _IO_getc_unlocked (s)), \
(void) (c != EOF && ++read_in), c))
__libc_cleanup_region_end (0)
#else
# 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 \
: ((c = getc (s)), (void) (c != EOF && ++read_in), c))
# define MEMCPY(d, s, n) memcpy (d, s, n)
if (wpsize == wpmax) \
{ \
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)); \
if (old != NULL) \
MEMCPY (wp, old, wpsize); \
#endif
#ifndef COMPILE_WSCANF
- if (!isascii (*f))
+ if (!isascii ((unsigned char) *f))
{
/* Non-ASCII, may be a multibyte. */
int len = __mbrlen (f, strlen (f), &state);
c = inchar ();
if (c == EOF)
input_error ();
- else if (c != *f++)
+ else if (c != (unsigned char) *f++)
{
- ungetc (c, s);
+ ungetc_not_eof (c, s);
conv_error ();
}
}
wpsize = 0;
/* Check for a positional parameter specification. */
- if (ISDIGIT (*f))
+ if (ISDIGIT ((UCHAR_T) *f))
{
- argpos = *f++ - L_('0');
- while (ISDIGIT (*f))
- argpos = argpos * 10 + (*f++ - L_('0'));
+ argpos = (UCHAR_T) *f++ - L_('0');
+ while (ISDIGIT ((UCHAR_T) *f))
+ argpos = argpos * 10 + ((UCHAR_T) *f++ - L_('0'));
if (*f == L_('$'))
++f;
else
}
/* We have seen width. */
- if (ISDIGIT (*f))
+ if (ISDIGIT ((UCHAR_T) *f))
flags |= WIDTH;
/* Find the maximum field width. */
width = 0;
- while (ISDIGIT (*f))
+ while (ISDIGIT ((UCHAR_T) *f))
{
width *= 10;
- width += *f++ - L_('0');
+ width += (UCHAR_T) *f++ - L_('0');
}
got_width:
if (width == 0)
input_error ();
if (c != fc)
{
- ungetc (c, s);
+ ungetc_not_eof (c, s);
conv_error ();
}
break;
{
if (ISSPACE (c))
{
- ungetc (c, s);
+ ungetc_not_eof (c, s);
break;
}
if (!(flags & SUPPRESS))
{
#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. */
char buf[MB_LEN_MAX];
size_t n = __wcrtomb (buf, L'\0', &state);
{
if (ISSPACE (c))
{
- ungetc (c, s);
+ ungetc_not_eof (c, s);
break;
}
mbdigits[n] = strchr (mbdigits[n], '\0') + 1;
cmpp = mbdigits[n];
- while (*cmpp == c && avail > 0)
+ while ((unsigned char) *cmpp == c && avail > 0)
{
if (*++cmpp == '\0')
break;
{
ungetc (c, s);
while (--cmpp > mbdigits[n])
- ungetc (*cmpp, s);
- c = *cmpp;
+ ungetc_not_eof ((unsigned char) *cmpp, s);
+ c = (unsigned char) *cmpp;
}
/* Advance the pointer to the next string. */
int avail = width > 0 ? width : INT_MAX;
cmpp = mbdigits[n];
- while (*cmpp == c && avail > 0)
+ while ((unsigned char) *cmpp == c && avail > 0)
{
if (*++cmpp == '\0')
break;
{
ungetc (c, s);
while (--cmpp > mbdigits[n])
- ungetc (*cmpp, s);
- c = *cmpp;
+ ungetc_not_eof ((unsigned char) *cmpp, s);
+ c = (unsigned char) *cmpp;
}
/* Advance the pointer to the next string. */
const char *cmpp = thousands;
int avail = width > 0 ? width : INT_MAX;
- while (*cmpp == c && avail > 0)
+ while ((unsigned char) *cmpp == c && avail > 0)
{
ADDW (c);
if (*++cmpp == '\0')
wpsize -= cmpp - thousands;
ungetc (c, s);
while (--cmpp > thousands)
- ungetc (*cmpp, s);
- c = *cmpp;
+ ungetc_not_eof ((unsigned char) *cmpp, s);
+ c = (unsigned char) *cmpp;
}
break;
}
const char *cmpp = thousands;
int avail = width > 0 ? width : INT_MAX;
- while (*cmpp == c && avail > 0)
+ while ((unsigned char) *cmpp == c && avail > 0)
{
ADDW (c);
if (*++cmpp == '\0')
wpsize -= cmpp - thousands;
ungetc (c, s);
while (--cmpp > thousands)
- ungetc (*cmpp, s);
- c = *cmpp;
+ ungetc_not_eof ((unsigned char) *cmpp, s);
+ c = (unsigned char) *cmpp;
}
break;
}
const char *cmpp = decimal;
int avail = width > 0 ? width : INT_MAX;
- while (*cmpp == c && avail > 0)
+ while ((unsigned char) *cmpp == c && avail > 0)
if (*++cmpp == '\0')
break;
else
ungetc (c, s);
if (cmpp == decimal)
break;
- c = *--cmpp;
+ c = (unsigned char) *--cmpp;
}
conv_error ();
if (! got_dot)
{
- while (*cmpp == c && avail > 0)
+ while ((unsigned char) *cmpp == c && avail > 0)
if (*++cmpp == '\0')
break;
else
{
/* Add all the characters. */
for (cmpp = decimal; *cmpp != '\0'; ++cmpp)
- ADDW (*cmpp);
+ ADDW ((unsigned char) *cmpp);
if (width > 0)
width = avail;
got_dot = 1;
++cmp2p;
if (cmp2p == cmpp)
{
- while (*cmp2p == c && avail > 0)
+ while ((unsigned char) *cmp2p == c && avail > 0)
if (*++cmp2p == '\0')
break;
else
{
/* Add all the characters. */
for (cmpp = thousands; *cmpp != '\0'; ++cmpp)
- ADDW (*cmpp);
+ ADDW ((unsigned char) *cmpp);
if (width > 0)
width = avail;
}
#else
/* Fill WP with byte flags indexed by character.
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);
}
- memset (wp, '\0', UCHAR_MAX);
+ memset (wp, '\0', UCHAR_MAX + 1);
fc = *f;
if (fc == ']' || fc == '-')
{
/* Add all characters from the one before the '-'
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;
}
else
if (wp[c] == not_in)
{
- ungetc (c, s);
+ ungetc_not_eof (c, s);
break;
}
if (wp[c] == not_in)
{
- ungetc (c, s);
+ ungetc_not_eof (c, s);
break;
}
if (!(flags & SUPPRESS))
{
#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. */
char buf[MB_LEN_MAX];
size_t n = __wcrtomb (buf, L'\0', &state);