Mercurial > hg > octave-nkf > gnulib-hg
changeset 4790:12ade6a1528e
Do not include <inttypes.h> or <stdint.h>.
(SIZE_MAX): Remove.
(new_exclude, add_exclude_file): Initial size no longer needs to
be a power of 2.
(add_exclude, add_exclude_file): Use xnrealloc instead of rolling
our own address arithmetic overflow checking.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Thu, 16 Oct 2003 05:26:15 +0000 |
parents | 39e294f843c2 |
children | c47569f6dfaa |
files | lib/exclude.c |
diffstat | 1 files changed, 6 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/exclude.c +++ b/lib/exclude.c @@ -35,23 +35,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#if HAVE_INTTYPES_H -# include <inttypes.h> -#else -# if HAVE_STDINT_H -# include <stdint.h> -# endif -#endif #include "exclude.h" #include "fnmatch.h" #include "unlocked-io.h" #include "xalloc.h" -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - #if STDC_HEADERS || (! defined isascii && ! HAVE_ISASCII) # define IN_CTYPE_DOMAIN(c) true #else @@ -106,7 +95,7 @@ { struct exclude *ex = xmalloc (sizeof *ex); ex->exclude_count = 0; - ex->exclude_alloc = (1 << 6); /* This must be a power of 2. */ + ex->exclude_alloc = 60; ex->exclude = xmalloc (ex->exclude_alloc * sizeof ex->exclude[0]); return ex; } @@ -201,11 +190,9 @@ if (ex->exclude_alloc <= ex->exclude_count) { - size_t s = 2 * ex->exclude_alloc; - if (! (0 < s && s <= SIZE_MAX / sizeof ex->exclude[0])) - xalloc_die (); - ex->exclude_alloc = s; - ex->exclude = xrealloc (ex->exclude, s * sizeof ex->exclude[0]); + ex->exclude = xnrealloc (ex->exclude, ex->exclude_alloc, + 2 * sizeof *ex->exclude); + ex->exclude_alloc *= 2; } patopts = &ex->exclude[ex->exclude_count++]; @@ -229,7 +216,7 @@ char *p; char const *pattern; char const *lim; - size_t buf_alloc = (1 << 10); /* This must be a power of two. */ + size_t buf_alloc = 1000; size_t buf_count = 0; int c; int e = 0; @@ -246,10 +233,8 @@ buf[buf_count++] = c; if (buf_count == buf_alloc) { + buf = xnrealloc (buf, buf_alloc, 2); buf_alloc *= 2; - if (! buf_alloc) - xalloc_die (); - buf = xrealloc (buf, buf_alloc); } }