From 4831ead44de7705efcffc76f5234fab59a7b1d9e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 25 Nov 2003 11:18:46 +0000 Subject: [PATCH] Use size_t instead of ssize_t. --- ChangeLog | 4 ++++ lib/ChangeLog | 15 ++++++++++++++- lib/printf-parse.c | 44 +++++++++++++++++--------------------------- lib/printf-parse.h | 12 ++++++------ lib/vasnprintf.c | 12 ++++++------ m4/ChangeLog | 5 +++++ m4/vasnprintf.m4 | 1 - modules/vasnprintf | 1 - 8 files changed, 52 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3fc3612ce..4067a7d3d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-11-25 Bruno Haible + + * modules/vasnprintf (Files): Remove m4/ssize_t.m4. + 2003-11-24 Paul Eggert * modules/alloca: Remove dependency on xalloc. diff --git a/lib/ChangeLog b/lib/ChangeLog index 7a84430fba..2d6b7e0179 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,6 +1,19 @@ +2003-11-23 Paul Eggert + Bruno Haible + + * printf-parse.h: Don't include sys/types.h. + (ARG_NONE): New macro. + (char_directive): Change type of *arg_index fields to size_t. + * printf-parse.c: Don't include sys/types.h. + (SSIZE_MAX): Remove macro. + (PRINTF_PARSE): Change the type of the arg_index variables to size_t. + Remove unnecessary overflow check. + * vasnprintf.c (VASNPRINTF): Update for type change of *arg_index + fields. + 2003-11-24 Paul Eggert - * lib/alloca.c: Remove dependency on xalloc module. + * alloca.c: Remove dependency on xalloc module. (xalloc_die): Remove. (memory_full) [!defined emacs]: New macro. [!defined emacs]: Don't include xalloc.h. diff --git a/lib/printf-parse.c b/lib/printf-parse.c index fceb5c97c0..b386b7b9b8 100644 --- a/lib/printf-parse.c +++ b/lib/printf-parse.c @@ -29,9 +29,6 @@ /* Get size_t, NULL. */ #include -/* Get ssize_t. */ -#include - /* Get intmax_t. */ #if HAVE_STDINT_H_WITH_UINTMAX # include @@ -46,10 +43,6 @@ /* Checked size_t computations. */ #include "xsize.h" -#ifndef SSIZE_MAX -# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) -#endif - #if WIDE_CHAR_VERSION # define PRINTF_PARSE wprintf_parse # define CHAR_T wchar_t @@ -69,7 +62,7 @@ int PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) { const CHAR_T *cp = format; /* pointer into format */ - ssize_t arg_posn = 0; /* number of regular arguments consumed */ + 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 max_width_length = 0; @@ -123,7 +116,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) CHAR_T c = *cp++; if (c == '%') { - ssize_t arg_index = -1; + size_t arg_index = ARG_NONE; DIRECTIVE *dp = &d->dir[d->count];/* pointer to next directive */ /* Initialize the next directive. */ @@ -131,11 +124,11 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) dp->flags = 0; dp->width_start = NULL; dp->width_end = NULL; - dp->width_arg_index = -1; + dp->width_arg_index = ARG_NONE; dp->precision_start = NULL; dp->precision_end = NULL; - dp->precision_arg_index = -1; - dp->arg_index = -1; + dp->precision_arg_index = ARG_NONE; + dp->arg_index = ARG_NONE; /* Test for positional argument. */ if (*cp >= '0' && *cp <= '9') @@ -153,7 +146,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) if (n == 0) /* Positional argument 0. */ goto error; - if (size_overflow_p (n) || n - 1 > SSIZE_MAX) + if (size_overflow_p (n)) /* n too large, would lead to out of memory later. */ goto error; arg_index = n - 1; @@ -223,18 +216,18 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) if (n == 0) /* Positional argument 0. */ goto error; - if (size_overflow_p (n) || n - 1 > SSIZE_MAX) + if (size_overflow_p (n)) /* n too large, would lead to out of memory later. */ goto error; dp->width_arg_index = n - 1; cp = np + 1; } } - if (dp->width_arg_index < 0) + if (dp->width_arg_index == ARG_NONE) { dp->width_arg_index = arg_posn++; - if (dp->width_arg_index < 0) - /* arg_posn wrapped around at SSIZE_MAX. */ + if (dp->width_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ goto error; } REGISTER_ARG (dp->width_arg_index, TYPE_INT); @@ -280,7 +273,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) if (n == 0) /* Positional argument 0. */ goto error; - if (size_overflow_p (n) || n - 1 > SSIZE_MAX) + if (size_overflow_p (n)) /* n too large, would lead to out of memory later. */ goto error; @@ -288,11 +281,11 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) cp = np + 1; } } - if (dp->precision_arg_index < 0) + if (dp->precision_arg_index == ARG_NONE) { dp->precision_arg_index = arg_posn++; - if (dp->precision_arg_index < 0) - /* arg_posn wrapped around at SSIZE_MAX. */ + if (dp->precision_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ goto error; } REGISTER_ARG (dp->precision_arg_index, TYPE_INT); @@ -491,11 +484,11 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) if (type != TYPE_NONE) { dp->arg_index = arg_index; - if (dp->arg_index < 0) + if (dp->arg_index == ARG_NONE) { dp->arg_index = arg_posn++; - if (dp->arg_index < 0) - /* arg_posn wrapped around at SSIZE_MAX. */ + if (dp->arg_index == ARG_NONE) + /* arg_posn wrapped around. */ goto error; } REGISTER_ARG (dp->arg_index, type); @@ -511,9 +504,6 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) DIRECTIVE *memory; d_allocated = xtimes (d_allocated, 2); - if (size_overflow_p (d_allocated)) - /* Overflow, would lead to out of memory. */ - goto error; memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); if (size_overflow_p (memory_size)) /* Overflow, would lead to out of memory. */ diff --git a/lib/printf-parse.h b/lib/printf-parse.h index 56f7cd280e..f3f4586606 100644 --- a/lib/printf-parse.h +++ b/lib/printf-parse.h @@ -20,9 +20,6 @@ #include "printf-args.h" -/* Get ssize_t. */ -#include - /* Flags */ #define FLAG_GROUP 1 /* ' flag */ @@ -32,6 +29,9 @@ #define FLAG_ALT 16 /* # flag */ #define FLAG_ZERO 32 +/* arg_index value indicating that no argument is consumed. */ +#define ARG_NONE (~(size_t)0) + /* A parsed directive. */ typedef struct { @@ -40,12 +40,12 @@ typedef struct int flags; const char* width_start; const char* width_end; - ssize_t width_arg_index; + size_t width_arg_index; const char* precision_start; const char* precision_end; - ssize_t precision_arg_index; + size_t precision_arg_index; char conversion; /* d i o u x X f e E g G c s p n U % but not C S */ - ssize_t arg_index; + size_t arg_index; } char_directive; diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index e40994d0c8..c0754ead9a 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -222,7 +222,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar { size_t augmented_length; - if (!(dp->arg_index < 0)) + if (!(dp->arg_index == ARG_NONE)) abort (); augmented_length = xsum (length, 1); ENSURE_ALLOCATION (augmented_length); @@ -231,7 +231,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar } else { - if (!(dp->arg_index >= 0)) + if (!(dp->arg_index != ARG_NONE)) abort (); if (dp->conversion == 'n') @@ -279,7 +279,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar width = 0; if (dp->width_start != dp->width_end) { - if (dp->width_arg_index >= 0) + if (dp->width_arg_index != ARG_NONE) { int arg; @@ -301,7 +301,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar precision = 6; if (dp->precision_start != dp->precision_end) { - if (dp->precision_arg_index >= 0) + if (dp->precision_arg_index != ARG_NONE) { int arg; @@ -563,13 +563,13 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar /* Construct the arguments for calling snprintf or sprintf. */ prefix_count = 0; - if (dp->width_arg_index >= 0) + if (dp->width_arg_index != ARG_NONE) { if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) abort (); prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; } - if (dp->precision_arg_index >= 0) + if (dp->precision_arg_index != ARG_NONE) { if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) abort (); diff --git a/m4/ChangeLog b/m4/ChangeLog index fe3163eee6..dc9d264c5e 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,8 @@ +2003-11-25 Bruno Haible + + * vasnprintf.m4 (gl_PREREQ_PRINTF_PARSE): Don't require + gt_TYPE_SSIZE_T. + 2003-11-17 Bruno Haible * vasnprintf.m4 (gl_PREREQ_PRINTF_PARSE): Require gt_TYPE_SSIZE_T. diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4 index a0bdc38659..d309f888ca 100644 --- a/m4/vasnprintf.m4 +++ b/m4/vasnprintf.m4 @@ -38,7 +38,6 @@ AC_DEFUN([gl_PREREQ_PRINTF_PARSE], AC_REQUIRE([gt_TYPE_WCHAR_T]) AC_REQUIRE([gt_TYPE_WINT_T]) AC_REQUIRE([AC_TYPE_SIZE_T]) - AC_REQUIRE([gt_TYPE_SSIZE_T]) AC_CHECK_TYPES(ptrdiff_t) AC_REQUIRE([gt_AC_TYPE_INTMAX_T]) ]) diff --git a/modules/vasnprintf b/modules/vasnprintf index 3d72d47e1a..ec42b66b37 100644 --- a/modules/vasnprintf +++ b/modules/vasnprintf @@ -15,7 +15,6 @@ m4/wchar_t.m4 m4/wint_t.m4 m4/longlong.m4 m4/intmax_t.m4 -m4/ssize_t.m4 m4/vasnprintf.m4 Depends-on: -- 2.30.2