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: In Prolog functions, don't assume int fits in size_t.
char *inbuffer;
char *in;
-int inbuffer_size;
+size_t inbuffer_size;
/* Return the current buffer position in the input file. */
available. */
static void *
-xmalloc (int nbytes)
+xmalloc (size_t nbytes)
{
void *p = malloc (nbytes);
if (p == NULL)
/* Like realloc but print an error and exit if out of memory. */
static void *
-xrealloc (void *p, int sz)
+xrealloc (void *p, size_t sz)
{
p = realloc (p, sz);
if (p == NULL)
static char *
operator_name (int *sc)
{
- static int id_size = 0;
+ static size_t id_size = 0;
static char *id = NULL;
const char *s;
- int len;
+ size_t len;
MATCH ();
len = strlen (s) + 10;
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_size = new_size;
}
}
else
{
- int tokens_matched = 0;
+ size_t tokens_matched = 0;
len = 20;
if (len > id_size)
len += strlen (s) + 2;
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_size = new_size;
}
fp = open_file (file);
if (fp)
{
- int nread, nbytes;
+ size_t nread, nbytes;
/* Give a progress indication if needed. */
if (f_very_verbose)
}
nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
- if (nbytes <= 0)
+ if (nbytes == 0)
break;
nread += nbytes;
}
- if (nread < 0)
- nread = 0;
inbuffer[nread] = '\0';
/* Reinitialize scanner and parser for the new input file. */