diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2011-03-22 18:01:59 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2011-03-22 18:01:59 -0700 |
commit | c9c49752e15c105ded153e9ab0a42743f57184e5 (patch) | |
tree | e395db95d87459082bace9fcf3a2cec0ea3d1aea /lib-src | |
parent | 9d0da923ebd2b78abb6e02f0b90cfe9d818eb301 (diff) | |
parent | b9b4b7cb4c27f9f6ad644168f0e1241e5c0d6eaa (diff) | |
download | emacs-c9c49752e15c105ded153e9ab0a42743f57184e5.tar.gz |
Fix more problems found by GCC 4.5.2's static checks.
Diffstat (limited to 'lib-src')
-rw-r--r-- | lib-src/ChangeLog | 30 | ||||
-rw-r--r-- | lib-src/Makefile.in | 2 | ||||
-rw-r--r-- | lib-src/ebrowse.c | 22 | ||||
-rw-r--r-- | lib-src/etags.c | 34 | ||||
-rw-r--r-- | lib-src/fakemail.c | 4 | ||||
-rw-r--r-- | lib-src/update-game-score.c | 14 |
6 files changed, 67 insertions, 39 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index bd1a84cf0b9..3df2f6881db 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,33 @@ +2011-03-23 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. + This avoids a warning with gcc -Wstrict-overflow. + * etags.c (Prolog_functions, prolog_pr, prolog_atom): Use size_t, + not int, to store sizes. + (prolog_atom): Return 0, not -1, on error. All callers changed. + + update-game-score: fix bug with -r + * update-game-score.c (main): Don't set 'scores' to garbage when + -r is specified and scorecount != MAX_SCORES (Bug#8310). This bug + was introduced in the 2002-04-10 change, and was found with gcc + -Wstrict-overflow (GCC 4.5.2, x86-64). + + fakemail: Remove dependency on ignore-value. + This undoes some of the recent fakemail-related changes. + It is made possible due to recent changes to gnulib's stdio module. + * Makefile.in (fakemail${EXEEXT}): Do not depend on ignore-value.h. + * fakemail.c: Do not include ignore-value.h. + (put_line): Do not use ignore_value. + 2011-03-03 Drake Wilson <drake@begriffli.ch> (tiny change) * emacsclient.c (longopts): Add quiet. diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in index d622233efb4..f671b0844ce 100644 --- a/lib-src/Makefile.in +++ b/lib-src/Makefile.in @@ -353,7 +353,7 @@ movemail.o: ${srcdir}/movemail.c ../src/config.h pop.o: ${srcdir}/pop.c ${srcdir}/../lib/min-max.h ../src/config.h $(CC) -c ${CPP_CFLAGS} ${MOVE_FLAGS} ${srcdir}/pop.c -fakemail${EXEEXT}: ${srcdir}/fakemail.c ${srcdir}/../lib/ignore-value.h ../src/config.h +fakemail${EXEEXT}: ${srcdir}/fakemail.c ../src/config.h $(CC) ${ALL_CFLAGS} ${srcdir}/fakemail.c $(LOADLIBES) -o fakemail emacsclient${EXEEXT}: ${srcdir}/emacsclient.c ../src/config.h diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c index 113b6fdfe40..7871a804997 100644 --- a/lib-src/ebrowse.c +++ b/lib-src/ebrowse.c @@ -378,7 +378,7 @@ int max_regexp = 50; char *inbuffer; char *in; -int inbuffer_size; +size_t inbuffer_size; /* Return the current buffer position in the input file. */ @@ -492,7 +492,7 @@ yyerror (const char *format, const char *s) available. */ static void * -xmalloc (int nbytes) +xmalloc (size_t nbytes) { void *p = malloc (nbytes); if (p == NULL) @@ -507,7 +507,7 @@ xmalloc (int nbytes) /* 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) @@ -2792,10 +2792,10 @@ parse_classname (void) 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 (); @@ -2811,7 +2811,7 @@ operator_name (int *sc) 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; } @@ -2832,7 +2832,7 @@ operator_name (int *sc) } else { - int tokens_matched = 0; + size_t tokens_matched = 0; len = 20; if (len > id_size) @@ -2853,7 +2853,7 @@ operator_name (int *sc) 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; } @@ -3550,7 +3550,7 @@ process_file (char *file) fp = open_file (file); if (fp) { - int nread, nbytes; + size_t nread, nbytes; /* Give a progress indication if needed. */ if (f_very_verbose) @@ -3574,12 +3574,10 @@ process_file (char *file) } 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. */ diff --git a/lib-src/etags.c b/lib-src/etags.c index 385e4cc9721..6cb321fe75e 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -4198,7 +4198,7 @@ Ada_funcs (FILE *inf) /* Skip a string i.e. "abcd". */ if (inquote || (*dbp == '"')) { - dbp = etags_strchr ((inquote) ? dbp : dbp+1, '"'); + dbp = etags_strchr (dbp + !inquote, '"'); if (dbp != NULL) { inquote = FALSE; @@ -5254,16 +5254,16 @@ HTML_labels (FILE *inf) * Original code by Sunichirou Sugou (1989) * Rewritten by Anders Lindgren (1996) */ -static int prolog_pr (char *, char *); +static size_t prolog_pr (char *, char *); static void prolog_skip_comment (linebuffer *, FILE *); -static int prolog_atom (char *, int); +static size_t prolog_atom (char *, size_t); static void Prolog_functions (FILE *inf) { char *cp, *last; - int len; - int allocated; + size_t len; + size_t allocated; allocated = 0; len = 0; @@ -5320,16 +5320,16 @@ prolog_skip_comment (linebuffer *plb, FILE *inf) * Return the size of the name of the predicate or rule, or 0 if no * header was found. */ -static int +static size_t prolog_pr (char *s, char *last) /* Name of last clause. */ { - int pos; - int len; + size_t pos; + size_t len; pos = prolog_atom (s, 0); - if (pos < 1) + if (! pos) return 0; len = pos; @@ -5339,7 +5339,7 @@ prolog_pr (char *s, char *last) || (s[pos] == '(' && (pos += 1)) || (s[pos] == ':' && s[pos + 1] == '-' && (pos += 2))) && (last == NULL /* save only the first clause */ - || len != (int)strlen (last) + || len != strlen (last) || !strneq (s, last, len))) { make_tag (s, len, TRUE, s, pos, lineno, linecharno); @@ -5351,17 +5351,17 @@ prolog_pr (char *s, char *last) /* * Consume a Prolog atom. - * Return the number of bytes consumed, or -1 if there was an error. + * Return the number of bytes consumed, or 0 if there was an error. * * A prolog atom, in this context, could be one of: * - An alphanumeric sequence, starting with a lower case letter. * - A quoted arbitrary string. Single quotes can escape themselves. * Backslash quotes everything. */ -static int -prolog_atom (char *s, int pos) +static size_t +prolog_atom (char *s, size_t pos) { - int origpos; + size_t origpos; origpos = pos; @@ -5390,11 +5390,11 @@ prolog_atom (char *s, int pos) } else if (s[pos] == '\0') /* Multiline quoted atoms are ignored. */ - return -1; + return 0; else if (s[pos] == '\\') { if (s[pos+1] == '\0') - return -1; + return 0; pos += 2; } else @@ -5403,7 +5403,7 @@ prolog_atom (char *s, int pos) return pos - origpos; } else - return -1; + return 0; } diff --git a/lib-src/fakemail.c b/lib-src/fakemail.c index 780a104b405..940d6219425 100644 --- a/lib-src/fakemail.c +++ b/lib-src/fakemail.c @@ -62,8 +62,6 @@ main () /* This is to declare cuserid. */ #include <unistd.h> - -#include <ignore-value.h> /* Type definitions */ @@ -500,7 +498,7 @@ put_line (const char *string) } } /* Output that much, then break the line. */ - ignore_value (fwrite (s, 1, breakpos - s, rem->handle)); + fwrite (s, 1, breakpos - s, rem->handle); column = 8; /* Skip whitespace and prepare to print more addresses. */ diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index 70b79a64f91..e95e2ce259d 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c @@ -242,13 +242,15 @@ main (int argc, char **argv) push_score (&scores, &scorecount, newscore, user_id, newdata); sort_scores (scores, scorecount, reverse); /* Limit the number of scores. If we're using reverse sorting, then - we should increment the beginning of the array, to skip over the - *smallest* scores. Otherwise, we just decrement the number of - scores, since the smallest will be at the end. */ + also increment the beginning of the array, to skip over the + *smallest* scores. Otherwise, just decrementing the number of + scores suffices, since the smallest is at the end. */ if (scorecount > MAX_SCORES) - scorecount -= (scorecount - MAX_SCORES); - if (reverse) - scores += (scorecount - MAX_SCORES); + { + if (reverse) + scores += (scorecount - MAX_SCORES); + scorecount = MAX_SCORES; + } if (write_scores (scorefile, scores, scorecount) < 0) { unlock_file (scorefile, lockstate); |