aboutsummaryrefslogtreecommitdiff
path: root/stdio-common/vfprintf.c
diff options
context:
space:
mode:
authorCarlos O'Donell <carlos@redhat.com>2017-05-08 16:11:45 -0400
committerCarlos O'Donell <carlos@redhat.com>2017-05-08 16:13:16 -0400
commit7224e32d7be41b39358defc0e33d2737307aa06a (patch)
tree4f55ab3bb92f8e6e569de4f2e7865d12a735a5f2 /stdio-common/vfprintf.c
parent1721145f0341d70a6d7807b172c5eb400b508fc0 (diff)
downloadglibc-7224e32d7be41b39358defc0e33d2737307aa06a.zip
glibc-7224e32d7be41b39358defc0e33d2737307aa06a.tar.gz
glibc-7224e32d7be41b39358defc0e33d2737307aa06a.tar.bz2
vfprintf.c: Refactor magic number 32 into EXTSIZ.
The magic number 32 is used everywhere as extra size to use when doing certain operations. This commit refactors that into a macro so you can change this value if you're debugging something in a local build.
Diffstat (limited to 'stdio-common/vfprintf.c')
-rw-r--r--stdio-common/vfprintf.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index 54b1ba2..2cf7c8a 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -45,6 +45,10 @@
#define va_list _IO_va_list
#undef BUFSIZ
#define BUFSIZ _IO_BUFSIZ
+/* In some cases we need extra space for all the output which is not
+ counted in the width of the string. We assume 32 characters is
+ enough. */
+#define EXTSIZ 32
#define ARGCHECK(S, Format) \
do \
{ \
@@ -1456,20 +1460,19 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
left = 1;
}
- if (__glibc_unlikely (width >= INT_MAX / sizeof (CHAR_T) - 32))
+ if (__glibc_unlikely (width >= INT_MAX / sizeof (CHAR_T) - EXTSIZ))
{
__set_errno (EOVERFLOW);
done = -1;
goto all_done;
}
- if (width >= WORK_BUFFER_SIZE - 32)
+ if (width >= WORK_BUFFER_SIZE - EXTSIZ)
{
- /* 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. */
- size_t needed = ((size_t) width + 32) * sizeof (CHAR_T);
+ /* We have to use a special buffer. */
+ size_t needed = ((size_t) width + EXTSIZ) * sizeof (CHAR_T);
if (__libc_use_alloca (needed))
- workend = (CHAR_T *) alloca (needed) + width + 32;
+ workend = (CHAR_T *) alloca (needed) + width + EXTSIZ;
else
{
workstart = (CHAR_T *) malloc (needed);
@@ -1478,7 +1481,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
done = -1;
goto all_done;
}
- workend = workstart + width + 32;
+ workend = workstart + width + EXTSIZ;
}
}
}
@@ -1489,20 +1492,19 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
width = read_int (&f);
if (__glibc_unlikely (width == -1
- || width >= INT_MAX / sizeof (CHAR_T) - 32))
+ || width >= INT_MAX / sizeof (CHAR_T) - EXTSIZ))
{
__set_errno (EOVERFLOW);
done = -1;
goto all_done;
}
- if (width >= WORK_BUFFER_SIZE - 32)
+ if (width >= WORK_BUFFER_SIZE - EXTSIZ)
{
- /* 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. */
- size_t needed = ((size_t) width + 32) * sizeof (CHAR_T);
+ /* We have to use a special buffer. */
+ size_t needed = ((size_t) width + EXTSIZ) * sizeof (CHAR_T);
if (__libc_use_alloca (needed))
- workend = (CHAR_T *) alloca (needed) + width + 32;
+ workend = (CHAR_T *) alloca (needed) + width + EXTSIZ;
else
{
workstart = (CHAR_T *) malloc (needed);
@@ -1511,7 +1513,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
done = -1;
goto all_done;
}
- workend = workstart + width + 32;
+ workend = workstart + width + EXTSIZ;
}
}
if (*f == L_('$'))
@@ -1562,23 +1564,23 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
}
else
prec = 0;
- if (prec > width && prec > WORK_BUFFER_SIZE - 32)
+ if (prec > width && prec > WORK_BUFFER_SIZE - EXTSIZ)
{
/* Deallocate any previously allocated buffer because it is
too small. */
if (__glibc_unlikely (workstart != NULL))
free (workstart);
workstart = NULL;
- if (__glibc_unlikely (prec >= INT_MAX / sizeof (CHAR_T) - 32))
+ if (__glibc_unlikely (prec >= INT_MAX / sizeof (CHAR_T) - EXTSIZ))
{
__set_errno (EOVERFLOW);
done = -1;
goto all_done;
}
- size_t needed = ((size_t) prec + 32) * sizeof (CHAR_T);
+ size_t needed = ((size_t) prec + EXTSIZ) * sizeof (CHAR_T);
if (__libc_use_alloca (needed))
- workend = (CHAR_T *) alloca (needed) + prec + 32;
+ workend = (CHAR_T *) alloca (needed) + prec + EXTSIZ;
else
{
workstart = (CHAR_T *) malloc (needed);
@@ -1587,7 +1589,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
done = -1;
goto all_done;
}
- workend = workstart + prec + 32;
+ workend = workstart + prec + EXTSIZ;
}
}
JUMP (*f, step2_jumps);
@@ -1964,23 +1966,23 @@ printf_positional (_IO_FILE *s, const CHAR_T *format, int readonly_format,
}
/* Maybe the buffer is too small. */
- if (MAX (prec, width) + 32 > WORK_BUFFER_SIZE)
+ if (MAX (prec, width) + EXTSIZ > WORK_BUFFER_SIZE)
{
- if (__libc_use_alloca ((MAX (prec, width) + 32)
+ if (__libc_use_alloca ((MAX (prec, width) + EXTSIZ)
* sizeof (CHAR_T)))
- workend = ((CHAR_T *) alloca ((MAX (prec, width) + 32)
+ workend = ((CHAR_T *) alloca ((MAX (prec, width) + EXTSIZ)
* sizeof (CHAR_T))
- + (MAX (prec, width) + 32));
+ + (MAX (prec, width) + EXTSIZ));
else
{
- workstart = (CHAR_T *) malloc ((MAX (prec, width) + 32)
+ workstart = (CHAR_T *) malloc ((MAX (prec, width) + EXTSIZ)
* sizeof (CHAR_T));
if (workstart == NULL)
{
done = -1;
goto all_done;
}
- workend = workstart + (MAX (prec, width) + 32);
+ workend = workstart + (MAX (prec, width) + EXTSIZ);
}
}