summaryrefslogtreecommitdiff
path: root/lib/printf-parse.c
diff options
context:
space:
mode:
authorStephen Kitt <skitt@debian.org>2016-05-27 10:11:04 +0200
committerManuel A. Fernandez Montecelo <manuel.montezelo@gmail.com>2016-05-27 14:28:33 +0100
commit752fd7247bc223bcea35bd89cf56d1c08ead9ba6 (patch)
treeb4a428f847a963738faaf24c8eff070fdb03a3a5 /lib/printf-parse.c
parent9f7d4fa477ff2a51d7c932b13d57ac22dc033105 (diff)
parenta9a31b1de5776a3b08a82101a4fa711294f0dd1d (diff)
Imported Debian patch 0.9.6+really0.9.3-0.1debian/0.9.6+really0.9.3-0.1
Diffstat (limited to 'lib/printf-parse.c')
-rw-r--r--lib/printf-parse.c55
1 files changed, 22 insertions, 33 deletions
diff --git a/lib/printf-parse.c b/lib/printf-parse.c
index b4592363..d88ddf30 100644
--- a/lib/printf-parse.c
+++ b/lib/printf-parse.c
@@ -1,5 +1,5 @@
/* Formatted output to strings.
- Copyright (C) 1999-2000, 2002-2003, 2006-2015 Free Software Foundation, Inc.
+ Copyright (C) 1999-2000, 2002-2003, 2006-2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -12,7 +12,8 @@
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
+ with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* This file can be parametrized with the following macros:
CHAR_T The element type of the format string.
@@ -62,9 +63,6 @@
/* malloc(), realloc(), free(). */
#include <stdlib.h>
-/* memcpy(). */
-#include <string.h>
-
/* errno. */
#include <errno.h>
@@ -82,20 +80,23 @@ STATIC
int
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
{
- const CHAR_T *cp = format; /* pointer into format */
+ const CHAR_T *cp = format; /* pointer into format */
size_t arg_posn = 0; /* number of regular arguments consumed */
- size_t d_allocated; /* allocated elements of d->dir */
- size_t a_allocated; /* allocated elements of a->arg */
+ size_t d_allocated; /* allocated elements of d->dir */
+ size_t a_allocated; /* allocated elements of a->arg */
size_t max_width_length = 0;
size_t max_precision_length = 0;
d->count = 0;
- d_allocated = N_DIRECT_ALLOC_DIRECTIVES;
- d->dir = d->direct_alloc_dir;
+ d_allocated = 1;
+ d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE));
+ if (d->dir == NULL)
+ /* Out of memory. */
+ goto out_of_memory_1;
a->count = 0;
- a_allocated = N_DIRECT_ALLOC_ARGUMENTS;
- a->arg = a->direct_alloc_arg;
+ a_allocated = 0;
+ a->arg = NULL;
#define REGISTER_ARG(_index_,_type_) \
{ \
@@ -112,14 +113,12 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
if (size_overflow_p (memory_size)) \
/* Overflow, would lead to out of memory. */ \
goto out_of_memory; \
- memory = (argument *) (a->arg != a->direct_alloc_arg \
+ memory = (argument *) (a->arg \
? realloc (a->arg, memory_size) \
: malloc (memory_size)); \
if (memory == NULL) \
/* Out of memory. */ \
goto out_of_memory; \
- if (a->arg == a->direct_alloc_arg) \
- memcpy (memory, a->arg, a->count * sizeof (argument)); \
a->arg = memory; \
} \
while (a->count <= n) \
@@ -207,13 +206,6 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
dp->flags |= FLAG_ZERO;
cp++;
}
-#if __GLIBC__ >= 2 && !defined __UCLIBC__
- else if (*cp == 'I')
- {
- dp->flags |= FLAG_LOCALIZED;
- cp++;
- }
-#endif
else
break;
}
@@ -401,7 +393,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
cp++;
}
#if defined __APPLE__ && defined __MACH__
- /* On Mac OS X 10.3, PRIdMAX is defined as "qd".
+ /* On MacOS X 10.3, PRIdMAX is defined as "qd".
We cannot change it to "lld" because PRIdMAX must also
be understood by the system's printf routines. */
else if (*cp == 'q')
@@ -420,7 +412,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
}
#endif
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- /* On native Windows, PRIdMAX is defined as "I64d".
+ /* On native Win32, PRIdMAX is defined as "I64d".
We cannot change it to "lld" because PRIdMAX must also
be understood by the system's printf routines. */
else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
@@ -589,14 +581,10 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
if (size_overflow_p (memory_size))
/* Overflow, would lead to out of memory. */
goto out_of_memory;
- memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir
- ? realloc (d->dir, memory_size)
- : malloc (memory_size));
+ memory = (DIRECTIVE *) realloc (d->dir, memory_size);
if (memory == NULL)
/* Out of memory. */
goto out_of_memory;
- if (d->dir == d->direct_alloc_dir)
- memcpy (memory, d->dir, d->count * sizeof (DIRECTIVE));
d->dir = memory;
}
}
@@ -615,18 +603,19 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
return 0;
error:
- if (a->arg != a->direct_alloc_arg)
+ if (a->arg)
free (a->arg);
- if (d->dir != d->direct_alloc_dir)
+ if (d->dir)
free (d->dir);
errno = EINVAL;
return -1;
out_of_memory:
- if (a->arg != a->direct_alloc_arg)
+ if (a->arg)
free (a->arg);
- if (d->dir != d->direct_alloc_dir)
+ if (d->dir)
free (d->dir);
+out_of_memory_1:
errno = ENOMEM;
return -1;
}