]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - stdio-common/printf-parse.h
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / stdio-common / printf-parse.h
index 72665dcec21e830a22842c7267e220c7214f8f75..603dea9d757c2ee6b9ea935d1cd71ba2ba3bcf65 100644 (file)
@@ -1,6 +1,5 @@
 /* Internal header for parsing printf format strings.
-   Copyright (C) 1995-1999, 2000, 2002, 2003, 2007, 2009
-   Free Software Foundation, Inc.
+   Copyright (C) 1995-2019 Free Software Foundation, Inc.
    This file is part of th GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -15,7 +14,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
 #include <printf.h>
 #include <stdint.h>
@@ -58,6 +57,9 @@ union printf_arg
     unsigned long long int pa_u_long_long_int;
     double pa_double;
     long double pa_long_double;
+#if __HAVE_FLOAT128_UNLIKE_LDBL
+    _Float128 pa_float128;
+#endif
     const char *pa_string;
     const wchar_t *pa_wstring;
     void *pa_pointer;
@@ -68,16 +70,27 @@ union printf_arg
 #ifndef DONT_NEED_READ_INT
 /* Read a simple integer from a string and update the string pointer.
    It is assumed that the first character is a digit.  */
-static unsigned int
+static int
 read_int (const UCHAR_T * *pstr)
 {
-  unsigned int retval = **pstr - L_('0');
+  int retval = **pstr - L_('0');
 
   while (ISDIGIT (*++(*pstr)))
-    {
-      retval *= 10;
-      retval += **pstr - L_('0');
-    }
+    if (retval >= 0)
+      {
+       if (INT_MAX / 10 < retval)
+         retval = -1;
+       else
+         {
+           int digit = **pstr - L_('0');
+
+           retval *= 10;
+           if (INT_MAX - digit < retval)
+             retval = -1;
+           else
+             retval += digit;
+         }
+      }
 
   return retval;
 }