1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

* ebrowse.c: Use size_t, not int, for sizes.

This avoids a warning with gcc -Wstrict-overflow, and works
better for very large objects.
(inbuffer_size): Now size_t.  All uses changed.
(xmalloc, xrealloc, operator_name, process_file): Use size_t for
sizes.  Don't bother testing whether a size_t value can be negative.
This commit is contained in:
Paul Eggert 2011-03-21 11:03:15 -07:00
parent 58cb46fbf4
commit b1f961e1fa
2 changed files with 17 additions and 12 deletions

View file

@ -1,5 +1,12 @@
2011-03-21 Paul Eggert <eggert@cs.ucla.edu> 2011-03-21 Paul Eggert <eggert@cs.ucla.edu>
* ebrowse.c: Use size_t, not int, for sizes.
This avoids a warning with gcc -Wstrict-overflow, and works
better for very large objects.
(inbuffer_size): Now size_t. All uses changed.
(xmalloc, xrealloc, operator_name, process_file): Use size_t for
sizes. Don't bother testing whether a size_t value can be negative.
* etags.c (Ada_funcs): Redo slightly to avoid overflow warning. * etags.c (Ada_funcs): Redo slightly to avoid overflow warning.
etags: In Prolog functions, don't assume int fits in size_t. etags: In Prolog functions, don't assume int fits in size_t.

View file

@ -378,7 +378,7 @@ int max_regexp = 50;
char *inbuffer; char *inbuffer;
char *in; char *in;
int inbuffer_size; size_t inbuffer_size;
/* Return the current buffer position in the input file. */ /* Return the current buffer position in the input file. */
@ -492,7 +492,7 @@ yyerror (const char *format, const char *s)
available. */ available. */
static void * static void *
xmalloc (int nbytes) xmalloc (size_t nbytes)
{ {
void *p = malloc (nbytes); void *p = malloc (nbytes);
if (p == NULL) if (p == NULL)
@ -507,7 +507,7 @@ xmalloc (int nbytes)
/* Like realloc but print an error and exit if out of memory. */ /* Like realloc but print an error and exit if out of memory. */
static void * static void *
xrealloc (void *p, int sz) xrealloc (void *p, size_t sz)
{ {
p = realloc (p, sz); p = realloc (p, sz);
if (p == NULL) if (p == NULL)
@ -2792,10 +2792,10 @@ parse_classname (void)
static char * static char *
operator_name (int *sc) operator_name (int *sc)
{ {
static int id_size = 0; static size_t id_size = 0;
static char *id = NULL; static char *id = NULL;
const char *s; const char *s;
int len; size_t len;
MATCH (); MATCH ();
@ -2811,7 +2811,7 @@ operator_name (int *sc)
len = strlen (s) + 10; len = strlen (s) + 10;
if (len > id_size) if (len > id_size)
{ {
int new_size = max (len, 2 * id_size); size_t new_size = max (len, 2 * id_size);
id = (char *) xrealloc (id, new_size); id = (char *) xrealloc (id, new_size);
id_size = new_size; id_size = new_size;
} }
@ -2832,7 +2832,7 @@ operator_name (int *sc)
} }
else else
{ {
int tokens_matched = 0; size_t tokens_matched = 0;
len = 20; len = 20;
if (len > id_size) if (len > id_size)
@ -2853,7 +2853,7 @@ operator_name (int *sc)
len += strlen (s) + 2; len += strlen (s) + 2;
if (len > id_size) if (len > id_size)
{ {
int new_size = max (len, 2 * id_size); size_t new_size = max (len, 2 * id_size);
id = (char *) xrealloc (id, new_size); id = (char *) xrealloc (id, new_size);
id_size = new_size; id_size = new_size;
} }
@ -3550,7 +3550,7 @@ process_file (char *file)
fp = open_file (file); fp = open_file (file);
if (fp) if (fp)
{ {
int nread, nbytes; size_t nread, nbytes;
/* Give a progress indication if needed. */ /* Give a progress indication if needed. */
if (f_very_verbose) if (f_very_verbose)
@ -3574,12 +3574,10 @@ process_file (char *file)
} }
nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp); nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
if (nbytes <= 0) if (nbytes == 0)
break; break;
nread += nbytes; nread += nbytes;
} }
if (nread < 0)
nread = 0;
inbuffer[nread] = '\0'; inbuffer[nread] = '\0';
/* Reinitialize scanner and parser for the new input file. */ /* Reinitialize scanner and parser for the new input file. */