aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2011-03-22 18:01:59 -0700
committerPaul Eggert2011-03-22 18:01:59 -0700
commitc9c49752e15c105ded153e9ab0a42743f57184e5 (patch)
treee395db95d87459082bace9fcf3a2cec0ea3d1aea /lib-src
parent9d0da923ebd2b78abb6e02f0b90cfe9d818eb301 (diff)
parentb9b4b7cb4c27f9f6ad644168f0e1241e5c0d6eaa (diff)
downloademacs-c9c49752e15c105ded153e9ab0a42743f57184e5.tar.gz
emacs-c9c49752e15c105ded153e9ab0a42743f57184e5.zip
Fix more problems found by GCC 4.5.2's static checks.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog30
-rw-r--r--lib-src/Makefile.in2
-rw-r--r--lib-src/ebrowse.c22
-rw-r--r--lib-src/etags.c34
-rw-r--r--lib-src/fakemail.c4
-rw-r--r--lib-src/update-game-score.c14
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 @@
12011-03-23 Paul Eggert <eggert@cs.ucla.edu>
2
3 * ebrowse.c: Use size_t, not int, for sizes.
4 This avoids a warning with gcc -Wstrict-overflow, and works
5 better for very large objects.
6 (inbuffer_size): Now size_t. All uses changed.
7 (xmalloc, xrealloc, operator_name, process_file): Use size_t for
8 sizes. Don't bother testing whether a size_t value can be negative.
9
10 * etags.c (Ada_funcs): Redo slightly to avoid overflow warning.
11
12 etags: In Prolog functions, don't assume int fits in size_t.
13 This avoids a warning with gcc -Wstrict-overflow.
14 * etags.c (Prolog_functions, prolog_pr, prolog_atom): Use size_t,
15 not int, to store sizes.
16 (prolog_atom): Return 0, not -1, on error. All callers changed.
17
18 update-game-score: fix bug with -r
19 * update-game-score.c (main): Don't set 'scores' to garbage when
20 -r is specified and scorecount != MAX_SCORES (Bug#8310). This bug
21 was introduced in the 2002-04-10 change, and was found with gcc
22 -Wstrict-overflow (GCC 4.5.2, x86-64).
23
24 fakemail: Remove dependency on ignore-value.
25 This undoes some of the recent fakemail-related changes.
26 It is made possible due to recent changes to gnulib's stdio module.
27 * Makefile.in (fakemail${EXEEXT}): Do not depend on ignore-value.h.
28 * fakemail.c: Do not include ignore-value.h.
29 (put_line): Do not use ignore_value.
30
12011-03-03 Drake Wilson <drake@begriffli.ch> (tiny change) 312011-03-03 Drake Wilson <drake@begriffli.ch> (tiny change)
2 32
3 * emacsclient.c (longopts): Add quiet. 33 * 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
353pop.o: ${srcdir}/pop.c ${srcdir}/../lib/min-max.h ../src/config.h 353pop.o: ${srcdir}/pop.c ${srcdir}/../lib/min-max.h ../src/config.h
354 $(CC) -c ${CPP_CFLAGS} ${MOVE_FLAGS} ${srcdir}/pop.c 354 $(CC) -c ${CPP_CFLAGS} ${MOVE_FLAGS} ${srcdir}/pop.c
355 355
356fakemail${EXEEXT}: ${srcdir}/fakemail.c ${srcdir}/../lib/ignore-value.h ../src/config.h 356fakemail${EXEEXT}: ${srcdir}/fakemail.c ../src/config.h
357 $(CC) ${ALL_CFLAGS} ${srcdir}/fakemail.c $(LOADLIBES) -o fakemail 357 $(CC) ${ALL_CFLAGS} ${srcdir}/fakemail.c $(LOADLIBES) -o fakemail
358 358
359emacsclient${EXEEXT}: ${srcdir}/emacsclient.c ../src/config.h 359emacsclient${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;
378 378
379char *inbuffer; 379char *inbuffer;
380char *in; 380char *in;
381int inbuffer_size; 381size_t inbuffer_size;
382 382
383/* Return the current buffer position in the input file. */ 383/* Return the current buffer position in the input file. */
384 384
@@ -492,7 +492,7 @@ yyerror (const char *format, const char *s)
492 available. */ 492 available. */
493 493
494static void * 494static void *
495xmalloc (int nbytes) 495xmalloc (size_t nbytes)
496{ 496{
497 void *p = malloc (nbytes); 497 void *p = malloc (nbytes);
498 if (p == NULL) 498 if (p == NULL)
@@ -507,7 +507,7 @@ xmalloc (int nbytes)
507/* Like realloc but print an error and exit if out of memory. */ 507/* Like realloc but print an error and exit if out of memory. */
508 508
509static void * 509static void *
510xrealloc (void *p, int sz) 510xrealloc (void *p, size_t sz)
511{ 511{
512 p = realloc (p, sz); 512 p = realloc (p, sz);
513 if (p == NULL) 513 if (p == NULL)
@@ -2792,10 +2792,10 @@ parse_classname (void)
2792static char * 2792static char *
2793operator_name (int *sc) 2793operator_name (int *sc)
2794{ 2794{
2795 static int id_size = 0; 2795 static size_t id_size = 0;
2796 static char *id = NULL; 2796 static char *id = NULL;
2797 const char *s; 2797 const char *s;
2798 int len; 2798 size_t len;
2799 2799
2800 MATCH (); 2800 MATCH ();
2801 2801
@@ -2811,7 +2811,7 @@ operator_name (int *sc)
2811 len = strlen (s) + 10; 2811 len = strlen (s) + 10;
2812 if (len > id_size) 2812 if (len > id_size)
2813 { 2813 {
2814 int new_size = max (len, 2 * id_size); 2814 size_t new_size = max (len, 2 * id_size);
2815 id = (char *) xrealloc (id, new_size); 2815 id = (char *) xrealloc (id, new_size);
2816 id_size = new_size; 2816 id_size = new_size;
2817 } 2817 }
@@ -2832,7 +2832,7 @@ operator_name (int *sc)
2832 } 2832 }
2833 else 2833 else
2834 { 2834 {
2835 int tokens_matched = 0; 2835 size_t tokens_matched = 0;
2836 2836
2837 len = 20; 2837 len = 20;
2838 if (len > id_size) 2838 if (len > id_size)
@@ -2853,7 +2853,7 @@ operator_name (int *sc)
2853 len += strlen (s) + 2; 2853 len += strlen (s) + 2;
2854 if (len > id_size) 2854 if (len > id_size)
2855 { 2855 {
2856 int new_size = max (len, 2 * id_size); 2856 size_t new_size = max (len, 2 * id_size);
2857 id = (char *) xrealloc (id, new_size); 2857 id = (char *) xrealloc (id, new_size);
2858 id_size = new_size; 2858 id_size = new_size;
2859 } 2859 }
@@ -3550,7 +3550,7 @@ process_file (char *file)
3550 fp = open_file (file); 3550 fp = open_file (file);
3551 if (fp) 3551 if (fp)
3552 { 3552 {
3553 int nread, nbytes; 3553 size_t nread, nbytes;
3554 3554
3555 /* Give a progress indication if needed. */ 3555 /* Give a progress indication if needed. */
3556 if (f_very_verbose) 3556 if (f_very_verbose)
@@ -3574,12 +3574,10 @@ process_file (char *file)
3574 } 3574 }
3575 3575
3576 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp); 3576 nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
3577 if (nbytes <= 0) 3577 if (nbytes == 0)
3578 break; 3578 break;
3579 nread += nbytes; 3579 nread += nbytes;
3580 } 3580 }
3581 if (nread < 0)
3582 nread = 0;
3583 inbuffer[nread] = '\0'; 3581 inbuffer[nread] = '\0';
3584 3582
3585 /* Reinitialize scanner and parser for the new input file. */ 3583 /* 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)
4198 /* Skip a string i.e. "abcd". */ 4198 /* Skip a string i.e. "abcd". */
4199 if (inquote || (*dbp == '"')) 4199 if (inquote || (*dbp == '"'))
4200 { 4200 {
4201 dbp = etags_strchr ((inquote) ? dbp : dbp+1, '"'); 4201 dbp = etags_strchr (dbp + !inquote, '"');
4202 if (dbp != NULL) 4202 if (dbp != NULL)
4203 { 4203 {
4204 inquote = FALSE; 4204 inquote = FALSE;
@@ -5254,16 +5254,16 @@ HTML_labels (FILE *inf)
5254 * Original code by Sunichirou Sugou (1989) 5254 * Original code by Sunichirou Sugou (1989)
5255 * Rewritten by Anders Lindgren (1996) 5255 * Rewritten by Anders Lindgren (1996)
5256 */ 5256 */
5257static int prolog_pr (char *, char *); 5257static size_t prolog_pr (char *, char *);
5258static void prolog_skip_comment (linebuffer *, FILE *); 5258static void prolog_skip_comment (linebuffer *, FILE *);
5259static int prolog_atom (char *, int); 5259static size_t prolog_atom (char *, size_t);
5260 5260
5261static void 5261static void
5262Prolog_functions (FILE *inf) 5262Prolog_functions (FILE *inf)
5263{ 5263{
5264 char *cp, *last; 5264 char *cp, *last;
5265 int len; 5265 size_t len;
5266 int allocated; 5266 size_t allocated;
5267 5267
5268 allocated = 0; 5268 allocated = 0;
5269 len = 0; 5269 len = 0;
@@ -5320,16 +5320,16 @@ prolog_skip_comment (linebuffer *plb, FILE *inf)
5320 * Return the size of the name of the predicate or rule, or 0 if no 5320 * Return the size of the name of the predicate or rule, or 0 if no
5321 * header was found. 5321 * header was found.
5322 */ 5322 */
5323static int 5323static size_t
5324prolog_pr (char *s, char *last) 5324prolog_pr (char *s, char *last)
5325 5325
5326 /* Name of last clause. */ 5326 /* Name of last clause. */
5327{ 5327{
5328 int pos; 5328 size_t pos;
5329 int len; 5329 size_t len;
5330 5330
5331 pos = prolog_atom (s, 0); 5331 pos = prolog_atom (s, 0);
5332 if (pos < 1) 5332 if (! pos)
5333 return 0; 5333 return 0;
5334 5334
5335 len = pos; 5335 len = pos;
@@ -5339,7 +5339,7 @@ prolog_pr (char *s, char *last)
5339 || (s[pos] == '(' && (pos += 1)) 5339 || (s[pos] == '(' && (pos += 1))
5340 || (s[pos] == ':' && s[pos + 1] == '-' && (pos += 2))) 5340 || (s[pos] == ':' && s[pos + 1] == '-' && (pos += 2)))
5341 && (last == NULL /* save only the first clause */ 5341 && (last == NULL /* save only the first clause */
5342 || len != (int)strlen (last) 5342 || len != strlen (last)
5343 || !strneq (s, last, len))) 5343 || !strneq (s, last, len)))
5344 { 5344 {
5345 make_tag (s, len, TRUE, s, pos, lineno, linecharno); 5345 make_tag (s, len, TRUE, s, pos, lineno, linecharno);
@@ -5351,17 +5351,17 @@ prolog_pr (char *s, char *last)
5351 5351
5352/* 5352/*
5353 * Consume a Prolog atom. 5353 * Consume a Prolog atom.
5354 * Return the number of bytes consumed, or -1 if there was an error. 5354 * Return the number of bytes consumed, or 0 if there was an error.
5355 * 5355 *
5356 * A prolog atom, in this context, could be one of: 5356 * A prolog atom, in this context, could be one of:
5357 * - An alphanumeric sequence, starting with a lower case letter. 5357 * - An alphanumeric sequence, starting with a lower case letter.
5358 * - A quoted arbitrary string. Single quotes can escape themselves. 5358 * - A quoted arbitrary string. Single quotes can escape themselves.
5359 * Backslash quotes everything. 5359 * Backslash quotes everything.
5360 */ 5360 */
5361static int 5361static size_t
5362prolog_atom (char *s, int pos) 5362prolog_atom (char *s, size_t pos)
5363{ 5363{
5364 int origpos; 5364 size_t origpos;
5365 5365
5366 origpos = pos; 5366 origpos = pos;
5367 5367
@@ -5390,11 +5390,11 @@ prolog_atom (char *s, int pos)
5390 } 5390 }
5391 else if (s[pos] == '\0') 5391 else if (s[pos] == '\0')
5392 /* Multiline quoted atoms are ignored. */ 5392 /* Multiline quoted atoms are ignored. */
5393 return -1; 5393 return 0;
5394 else if (s[pos] == '\\') 5394 else if (s[pos] == '\\')
5395 { 5395 {
5396 if (s[pos+1] == '\0') 5396 if (s[pos+1] == '\0')
5397 return -1; 5397 return 0;
5398 pos += 2; 5398 pos += 2;
5399 } 5399 }
5400 else 5400 else
@@ -5403,7 +5403,7 @@ prolog_atom (char *s, int pos)
5403 return pos - origpos; 5403 return pos - origpos;
5404 } 5404 }
5405 else 5405 else
5406 return -1; 5406 return 0;
5407} 5407}
5408 5408
5409 5409
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 ()
62 62
63/* This is to declare cuserid. */ 63/* This is to declare cuserid. */
64#include <unistd.h> 64#include <unistd.h>
65
66#include <ignore-value.h>
67 65
68/* Type definitions */ 66/* Type definitions */
69 67
@@ -500,7 +498,7 @@ put_line (const char *string)
500 } 498 }
501 } 499 }
502 /* Output that much, then break the line. */ 500 /* Output that much, then break the line. */
503 ignore_value (fwrite (s, 1, breakpos - s, rem->handle)); 501 fwrite (s, 1, breakpos - s, rem->handle);
504 column = 8; 502 column = 8;
505 503
506 /* Skip whitespace and prepare to print more addresses. */ 504 /* 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)
242 push_score (&scores, &scorecount, newscore, user_id, newdata); 242 push_score (&scores, &scorecount, newscore, user_id, newdata);
243 sort_scores (scores, scorecount, reverse); 243 sort_scores (scores, scorecount, reverse);
244 /* Limit the number of scores. If we're using reverse sorting, then 244 /* Limit the number of scores. If we're using reverse sorting, then
245 we should increment the beginning of the array, to skip over the 245 also increment the beginning of the array, to skip over the
246 *smallest* scores. Otherwise, we just decrement the number of 246 *smallest* scores. Otherwise, just decrementing the number of
247 scores, since the smallest will be at the end. */ 247 scores suffices, since the smallest is at the end. */
248 if (scorecount > MAX_SCORES) 248 if (scorecount > MAX_SCORES)
249 scorecount -= (scorecount - MAX_SCORES); 249 {
250 if (reverse) 250 if (reverse)
251 scores += (scorecount - MAX_SCORES); 251 scores += (scorecount - MAX_SCORES);
252 scorecount = MAX_SCORES;
253 }
252 if (write_scores (scorefile, scores, scorecount) < 0) 254 if (write_scores (scorefile, scores, scorecount) < 0)
253 { 255 {
254 unlock_file (scorefile, lockstate); 256 unlock_file (scorefile, lockstate);