]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
vfprintf: Define WORK_BUFFER_SIZE
authorFlorian Weimer <fweimer@redhat.com>
Sun, 1 Mar 2015 20:52:15 +0000 (21:52 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 6 Mar 2015 10:06:33 +0000 (11:06 +0100)
This constant will allow us to refer to the number of elements in
work_buffer across a function call boundary.

ChangeLog
stdio-common/vfprintf.c

index 94a2402459011c57f9518f91e5cb0f580e1edf91..c422a3794889321345b4a3a51bf38c8eeb93f5f5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,8 +2,10 @@
 
        * stdio-common/vfprintf.c (THOUSANDS_SEP_T): New typedef.
        (group_number, vfprintf): Use it.
-        (JUMP_TABLE_BASE_LABEL): New preprocessor macro.
-        (JUMP, REF): Use it.
+       (JUMP_TABLE_BASE_LABEL): New preprocessor macro.
+       (JUMP, REF): Use it.
+       (WORK_BUFFER_SIZE): New enum constant.
+       (process_arg, vfprintf): Use it.
 
 2015-03-06  Rical Jasan  <ricaljasan@pacific.net>
 
index 030d33d981052e9608ccbb9a8a28cd974103e21e..0e435f2a75c7cb1eedf1e118be0aa820054c3248 100644 (file)
@@ -196,9 +196,11 @@ typedef wchar_t THOUSANDS_SEP_T;
 #endif
 
 
-/* Global variables.  */
+/* Global constants.  */
 static const CHAR_T null[] = L_("(null)");
 
+/* Size of the work_buffer variable (in characters, not bytes.  */
+enum { WORK_BUFFER_SIZE = 1000 };
 
 /* Helper function to provide temporary buffering for unbuffered streams.  */
 static int buffered_vfprintf (FILE *stream, const CHAR_T *fmt, va_list)
@@ -235,7 +237,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
   const UCHAR_T *end_of_spec;
 
   /* Buffer intermediate results.  */
-  CHAR_T work_buffer[1000];
+  CHAR_T work_buffer[WORK_BUFFER_SIZE];
   CHAR_T *workstart = NULL;
   CHAR_T *workend;
 
@@ -986,7 +988,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       /* Print description of error ERRNO.  */                               \
       string =                                                               \
        (CHAR_T *) __strerror_r (save_errno, (char *) work_buffer,            \
-                                sizeof work_buffer);                         \
+                                WORK_BUFFER_SIZE * sizeof (CHAR_T));         \
       is_long = 0;             /* This is no wide-char string.  */           \
       goto LABEL (print_string)
 
@@ -1366,7 +1368,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
       CHAR_T spec;
 
       workstart = NULL;
-      workend = &work_buffer[sizeof (work_buffer) / sizeof (CHAR_T)];
+      workend = work_buffer + WORK_BUFFER_SIZE;
 
       /* Get current character in format string.  */
       JUMP (*++f, step0_jumps);
@@ -1465,7 +1467,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
            goto all_done;
          }
 
-       if (width >= sizeof (work_buffer) / sizeof (work_buffer[0]) - 32)
+       if (width >= WORK_BUFFER_SIZE - 32)
          {
            /* We have to use a special buffer.  The "32" is just a safe
               bet for all the output which is not counted in the width.  */
@@ -1498,7 +1500,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
          goto all_done;
        }
 
-      if (width >= sizeof (work_buffer) / sizeof (work_buffer[0]) - 32)
+      if (width >= WORK_BUFFER_SIZE - 32)
        {
          /* We have to use a special buffer.  The "32" is just a safe
             bet for all the output which is not counted in the width.  */
@@ -1564,8 +1566,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
        }
       else
        prec = 0;
-      if (prec > width
-         && prec > sizeof (work_buffer) / sizeof (work_buffer[0]) - 32)
+      if (prec > width && prec > WORK_BUFFER_SIZE - 32)
        {
          if (__glibc_unlikely (prec >= INT_MAX / sizeof (CHAR_T) - 32))
            {
@@ -1935,7 +1936,7 @@ do_positional:
        CHAR_T spec = specs[nspecs_done].info.spec;
 
        workstart = NULL;
-       workend = &work_buffer[sizeof (work_buffer) / sizeof (CHAR_T)];
+       workend = work_buffer + WORK_BUFFER_SIZE;
 
        /* Fill in last information.  */
        if (specs[nspecs_done].width_arg != -1)
@@ -1969,8 +1970,7 @@ do_positional:
          }
 
        /* Maybe the buffer is too small.  */
-       if (MAX (prec, width) + 32 > (int) (sizeof (work_buffer)
-                                           / sizeof (CHAR_T)))
+       if (MAX (prec, width) + 32 > WORK_BUFFER_SIZE)
          {
            if (__libc_use_alloca ((MAX (prec, width) + 32)
                                   * sizeof (CHAR_T)))