aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2011-03-21 11:03:15 -0700
committerPaul Eggert2011-03-21 11:03:15 -0700
commitb1f961e1fa871419e3e75759ad2fefee032ebff5 (patch)
tree4c399696c8e55f7cc661dcd04ab9654fdf6a89be /lib-src
parent58cb46fbf4a0d3b37cb9cf2b07446eaa48663693 (diff)
downloademacs-b1f961e1fa871419e3e75759ad2fefee032ebff5.tar.gz
emacs-b1f961e1fa871419e3e75759ad2fefee032ebff5.zip
* 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.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog7
-rw-r--r--lib-src/ebrowse.c22
2 files changed, 17 insertions, 12 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 6c25f582eea..909bee743bb 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,5 +1,12 @@
12011-03-21 Paul Eggert <eggert@cs.ucla.edu> 12011-03-21 Paul Eggert <eggert@cs.ucla.edu>
2 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
3 * etags.c (Ada_funcs): Redo slightly to avoid overflow warning. 10 * etags.c (Ada_funcs): Redo slightly to avoid overflow warning.
4 11
5 etags: In Prolog functions, don't assume int fits in size_t. 12 etags: In Prolog functions, don't assume int fits in size_t.
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. */