From: Paul Eggert Date: Thu, 16 Oct 2003 05:26:15 +0000 (+0000) Subject: Do not include or . X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6942bbb52b3b0cdbdedcdf8b4356387631a2e8f3;p=pspp Do not include or . (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. --- diff --git a/lib/exclude.c b/lib/exclude.c index 3d1d3bfcb0..cb43326667 100644 --- a/lib/exclude.c +++ b/lib/exclude.c @@ -35,23 +35,12 @@ extern int errno; #include #include #include -#if HAVE_INTTYPES_H -# include -#else -# if HAVE_STDINT_H -# include -# 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 @@ new_exclude (void) { 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 @@ add_exclude (struct exclude *ex, char const *pattern, int options) 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 @@ add_exclude_file (void (*add_func) (struct exclude *, char const *, int), 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 @@ add_exclude_file (void (*add_func) (struct exclude *, char const *, int), 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); } }