summaryrefslogtreecommitdiff
path: root/stdio-common/vfscanf.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2016-08-20 19:50:45 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2016-08-20 19:50:45 +0200
commit4dd9e35bfd35d3138bc44169baba098005bad51e (patch)
treea4939c43a9c3fe00eb27f023e14acc5e1fe8808c /stdio-common/vfscanf.c
parentbd42a4599d1b6f77bcfe1e4f67b7cbd9e1cb2dfd (diff)
parentf76453c31593957fec1a99b986bfa5506618b79c (diff)
Merge commit 'refs/top-bases/t/bigmem' into t/bigmem
Diffstat (limited to 'stdio-common/vfscanf.c')
-rw-r--r--stdio-common/vfscanf.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
index 2e1e91af78..0e204e7b32 100644
--- a/stdio-common/vfscanf.c
+++ b/stdio-common/vfscanf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2015 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
@@ -269,12 +269,13 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
#define ADDW(Ch) \
do \
{ \
- if (__builtin_expect (wpsize == wpmax, 0)) \
+ if (__glibc_unlikely (wpsize == wpmax)) \
{ \
CHAR_T *old = wp; \
- size_t newsize = (UCHAR_MAX + 1 > 2 * wpmax \
- ? UCHAR_MAX + 1 : 2 * wpmax); \
- if (use_malloc || !__libc_use_alloca (newsize)) \
+ bool fits = __glibc_likely (wpmax <= SIZE_MAX / sizeof (CHAR_T) / 2); \
+ size_t wpneed = MAX (UCHAR_MAX + 1, 2 * wpmax); \
+ size_t newsize = fits ? wpneed * sizeof (CHAR_T) : SIZE_MAX; \
+ if (!__libc_use_alloca (newsize)) \
{ \
wp = realloc (use_malloc ? wp : NULL, newsize); \
if (wp == NULL) \
@@ -286,14 +287,13 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
} \
if (! use_malloc) \
MEMCPY (wp, old, wpsize); \
- wpmax = newsize; \
+ wpmax = wpneed; \
use_malloc = true; \
} \
else \
{ \
size_t s = wpmax * sizeof (CHAR_T); \
- wp = (CHAR_T *) extend_alloca (wp, s, \
- newsize * sizeof (CHAR_T)); \
+ wp = (CHAR_T *) extend_alloca (wp, s, newsize); \
wpmax = s / sizeof (CHAR_T); \
if (old != NULL) \
MEMCPY (wp, old, wpsize); \
@@ -392,7 +392,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
do
{
c = inchar ();
- if (__builtin_expect (c == EOF, 0))
+ if (__glibc_unlikely (c == EOF))
input_error ();
else if (c != (unsigned char) *f++)
{
@@ -420,7 +420,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
c = inchar ();
/* Characters other than format specs must just match. */
- if (__builtin_expect (c == EOF, 0))
+ if (__glibc_unlikely (c == EOF))
input_error ();
/* We saw white space char as the last character in the format
@@ -428,12 +428,12 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
if (skip_space)
{
while (ISSPACE (c))
- if (__builtin_expect (inchar () == EOF, 0))
+ if (__glibc_unlikely (inchar () == EOF))
input_error ();
skip_space = 0;
}
- if (__builtin_expect (c != fc, 0))
+ if (__glibc_unlikely (c != fc))
{
ungetc (c, s);
conv_error ();
@@ -581,7 +581,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
}
/* End of the format string? */
- if (__builtin_expect (*f == L_('\0'), 0))
+ if (__glibc_unlikely (*f == L_('\0')))
conv_error ();
/* Find the conversion specifier. */
@@ -610,9 +610,9 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
{
case L_('%'): /* Must match a literal '%'. */
c = inchar ();
- if (__builtin_expect (c == EOF, 0))
+ if (__glibc_unlikely (c == EOF))
input_error ();
- if (__builtin_expect (c != fc, 0))
+ if (__glibc_unlikely (c != fc))
{
ungetc_not_eof (c, s);
conv_error ();
@@ -710,7 +710,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
#endif
c = inchar ();
- if (__builtin_expect (c == EOF, 0))
+ if (__glibc_unlikely (c == EOF))
input_error ();
#ifdef COMPILE_WSCANF
@@ -758,7 +758,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
}
n = __wcrtomb (!(flags & SUPPRESS) ? str : NULL, c, &state);
- if (__builtin_expect (n == (size_t) -1, 0))
+ if (__glibc_unlikely (n == (size_t) -1))
/* No valid wide character. */
input_error ();
@@ -836,7 +836,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
STRING_ARG (wstr, wchar_t, (width > 1024 ? 1024 : width));
c = inchar ();
- if (__builtin_expect (c == EOF, 0))
+ if (__glibc_unlikely (c == EOF))
input_error ();
#ifdef COMPILE_WSCANF
@@ -946,14 +946,14 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
{
/* Possibly correct character, just not enough
input. */
- if (__builtin_expect (inchar () == EOF, 0))
+ if (__glibc_unlikely (inchar () == EOF))
encode_error ();
buf[0] = c;
continue;
}
- if (__builtin_expect (n != 1, 0))
+ if (__glibc_unlikely (n != 1))
encode_error ();
/* We have a match. */
@@ -991,7 +991,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
STRING_ARG (str, char, 100);
c = inchar ();
- if (__builtin_expect (c == EOF, 0))
+ if (__glibc_unlikely (c == EOF))
input_error ();
#ifdef COMPILE_WSCANF
@@ -1060,7 +1060,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
n = __wcrtomb (!(flags & SUPPRESS) ? str : NULL, c,
&state);
- if (__builtin_expect (n == (size_t) -1, 0))
+ if (__glibc_unlikely (n == (size_t) -1))
encode_error ();
assert (n <= MB_CUR_MAX);
@@ -1262,14 +1262,14 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
{
/* Possibly correct character, just not enough
input. */
- if (__builtin_expect (inchar () == EOF, 0))
+ if (__glibc_unlikely (inchar () == EOF))
encode_error ();
buf[0] = c;
continue;
}
- if (__builtin_expect (n != 1, 0))
+ if (__glibc_unlikely (n != 1))
encode_error ();
/* We have a match. */
@@ -1368,7 +1368,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
number:
c = inchar ();
- if (__builtin_expect (c == EOF, 0))
+ if (__glibc_unlikely (c == EOF))
input_error ();
/* Check for a sign. */
@@ -1434,7 +1434,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
#endif
/* Get the alternative digit forms if there are any. */
- if (__builtin_expect (map != NULL, 0))
+ if (__glibc_unlikely (map != NULL))
{
/* Adding new level for extra digits set in locale file. */
++to_level;
@@ -1502,7 +1502,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
{
/* Get the string for the digits with value N. */
#ifdef COMPILE_WSCANF
- if (__builtin_expect (map != NULL, 0))
+ if (__glibc_unlikely (map != NULL))
wcdigits[n] = wcdigits_extended[n];
else
wcdigits[n] = (const wchar_t *)
@@ -1521,7 +1521,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
const char *cmpp;
int avail = width > 0 ? width : INT_MAX;
- if (__builtin_expect (map != NULL, 0))
+ if (__glibc_unlikely (map != NULL))
mbdigits[n] = mbdigits_extended[n];
else
mbdigits[n]
@@ -1795,7 +1795,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
else
num.ul = __strtoul_internal (wp, &tw, base, flags & GROUP);
}
- if (__builtin_expect (wp == tw, 0))
+ if (__glibc_unlikely (wp == tw))
conv_error ();
if (!(flags & SUPPRESS))
@@ -1842,7 +1842,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
c = inchar ();
if (width > 0)
--width;
- if (__builtin_expect (c == EOF, 0))
+ if (__glibc_unlikely (c == EOF))
input_error ();
got_digit = got_dot = got_e = 0;
@@ -1851,7 +1851,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
if (c == L_('-') || c == L_('+'))
{
negative = c == L_('-');
- if (__builtin_expect (width == 0 || inchar () == EOF, 0))
+ if (__glibc_unlikely (width == 0 || inchar () == EOF))
/* EOF is only an input error before we read any chars. */
conv_error ();
if (width > 0)
@@ -2334,7 +2334,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
*ARG (float *) = negative ? -d : d;
}
- if (__builtin_expect (tw == wp, 0))
+ if (__glibc_unlikely (tw == wp))
conv_error ();
if (!(flags & SUPPRESS))
@@ -2374,7 +2374,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
while ((fc = *f++) != L'\0' && fc != L']');
- if (__builtin_expect (fc == L'\0', 0))
+ if (__glibc_unlikely (fc == L'\0'))
conv_error ();
wchar_t *twend = (wchar_t *) f - 1;
#else
@@ -2410,7 +2410,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
/* Add the character to the flag map. */
wp[fc] = 1;
- if (__builtin_expect (fc == '\0', 0))
+ if (__glibc_unlikely (fc == '\0'))
conv_error();
#endif
@@ -2418,7 +2418,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
{
size_t now = read_in;
#ifdef COMPILE_WSCANF
- if (__builtin_expect (inchar () == WEOF, 0))
+ if (__glibc_unlikely (inchar () == WEOF))
input_error ();
do
@@ -2530,7 +2530,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
size_t cnt = 0;
mbstate_t cstate;
- if (__builtin_expect (inchar () == EOF, 0))
+ if (__glibc_unlikely (inchar () == EOF))
input_error ();
memset (&cstate, '\0', sizeof (cstate));
@@ -2613,13 +2613,13 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
}
while (inchar () != EOF);
- if (__builtin_expect (cnt != 0, 0))
+ if (__glibc_unlikely (cnt != 0))
/* We stopped in the middle of recognizing another
character. That's a problem. */
encode_error ();
#endif
- if (__builtin_expect (now == read_in, 0))
+ if (__glibc_unlikely (now == read_in))
/* We haven't succesfully read any character. */
conv_error ();
@@ -2645,7 +2645,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
{
size_t now = read_in;
- if (__builtin_expect (inchar () == EOF, 0))
+ if (__glibc_unlikely (inchar () == EOF))
input_error ();
#ifdef COMPILE_WSCANF
@@ -2754,7 +2754,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
}
n = __wcrtomb (!(flags & SUPPRESS) ? str : NULL, c, &state);
- if (__builtin_expect (n == (size_t) -1, 0))
+ if (__glibc_unlikely (n == (size_t) -1))
encode_error ();
assert (n <= MB_CUR_MAX);
@@ -2817,7 +2817,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
while (--width > 0 && inchar () != EOF);
#endif
- if (__builtin_expect (now == read_in, 0))
+ if (__glibc_unlikely (now == read_in))
/* We haven't succesfully read any character. */
conv_error ();
@@ -2911,9 +2911,9 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
if (errp != NULL)
*errp |= errval;
- if (__builtin_expect (done == EOF, 0))
+ if (__glibc_unlikely (done == EOF))
{
- if (__builtin_expect (ptrs_to_free != NULL, 0))
+ if (__glibc_unlikely (ptrs_to_free != NULL))
{
struct ptrs_to_free *p = ptrs_to_free;
while (p != NULL)
@@ -2928,7 +2928,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
}
}
}
- else if (__builtin_expect (strptr != NULL, 0))
+ else if (__glibc_unlikely (strptr != NULL))
{
free (*strptr);
*strptr = NULL;