This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

cpplib warnings patch



This patch eliminates all the warnings in cpplib except two.  Those
two are caused by some tense and hairy code in finclude() that I don't
want to muck with.

Most of the warnings are either due to confusion of size_t with
ptrdiff_t, or to use of signed int for buffer sizes.

zw

1998-10-02 20:42 -0400  Zack Weinberg  <zack@rabi.phys.columbia.edu>

	* cppexp.c: When forcing unsigned comparisons, cast both sides
	of the operation.

	* cpphash.h: Move static declaration of hashtab[]...
	* cpphash.c: ...here.

	* cpplib.c: Cast difference of two pointers to size_t before
	comparing it to size_t.  Cast signed to unsigned
	before comparing to size_t. (FIXME: struct argdata should use
	unsigned buffer sizes.)
	* cpplib.h (struct cpp_reader): Declare token_buffer_size as
	unsigned int. (CPP_WRITTEN): Cast return value to size_t.
	(CPP_RESERVE): Parenthesize N for evaluation order, cast to
	size_t before comparison.

--- cppexp.c.warn	Fri Oct  2 20:28:31 1998
+++ cppexp.c	Fri Oct  2 20:30:07 1998
@@ -365,7 +365,7 @@
 	      {
 		c = cpp_parse_escape (pfile, (char **) &ptr);
 		if (width < HOST_BITS_PER_INT
-		  && (unsigned) c >= (1 << width))
+		  && (unsigned) c >= (unsigned)(1 << width))
 		    cpp_pedwarn (pfile,
 				 "escape sequence out of range for character");
 	      }
@@ -649,7 +649,8 @@
 
 #define COMPARE(OP) \
   top->unsignedp = 0;\
-  top->value = (unsigned1 || unsigned2) ? (unsigned long) v1 OP v2 : (v1 OP v2)
+  top->value = (unsigned1 || unsigned2) \
+  ? (unsigned long) v1 OP (unsigned long) v2 : (v1 OP v2)
 
 /* Parse and evaluate a C expression, reading from PFILE.
    Returns the value of the expression.  */
--- cpphash.c.warn	Fri Oct  2 20:27:30 1998
+++ cpphash.c	Fri Oct  2 20:27:54 1998
@@ -30,6 +30,8 @@
 
 extern char *xmalloc PARAMS ((unsigned));
 
+static HASHNODE *hashtab[HASHSIZE];
+
 /* Return hash function on name.  must be compatible with the one
    computed a step at a time, elsewhere  */
 
--- cpphash.h.warn	Fri Oct  2 20:27:37 1998
+++ cpphash.h	Fri Oct  2 20:27:44 1998
@@ -31,7 +31,6 @@
    politeness, for use when speed isn't so important. */
 
 #define HASHSIZE 1403
-static HASHNODE *hashtab[HASHSIZE];
 #define HASHSTEP(old, c) ((old << 2) + c)
 #define MAKE_POS(v) (v & 0x7fffffff) /* make number positive */
 
--- cpplib.c.warn	Fri Oct  2 20:25:06 1998
+++ cpplib.c	Fri Oct  2 20:39:15 1998
@@ -1512,7 +1512,7 @@
       while (is_idchar[*bp]) {
 	bp++;
 	/* do we have a "special" rest-args extension here? */
-	if (limit - bp > REST_EXTENSION_LENGTH
+	if ((size_t)(limit - bp) > REST_EXTENSION_LENGTH
 	    && strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
 	  rest_args = 1;
 	  temp->rest_args = 1;
@@ -2747,7 +2747,7 @@
 			     one space except within an string or char token.*/
 			  if (is_space[c])
 			    {
-			      if (CPP_WRITTEN (pfile) > arg->stringified
+			      if (CPP_WRITTEN (pfile) > (unsigned)arg->stringified
 				  && (CPP_PWRITTEN (pfile))[-1] == '@')
 				{
 				  /* "@ " escape markers are removed */
@@ -5531,7 +5531,7 @@
 	p = filename;
       if (searchptr
 	  && searchptr->fname
-	  && strlen (searchptr->fname) == p - filename
+	  && strlen (searchptr->fname) == (size_t) (p - filename)
 	  && ! strncmp (searchptr->fname, filename, p - filename))
 	{
 	  /* FILENAME is in SEARCHPTR, which we've already checked.  */
--- cpplib.h.warn	Fri Oct  2 20:25:01 1998
+++ cpplib.h	Fri Oct  2 20:32:22 1998
@@ -177,7 +177,7 @@
   /* A buffer used for both for cpp_get_token's output, and also internally. */
   unsigned char *token_buffer;
   /* Allocated size of token_buffer.  CPP_RESERVE allocates space.  */
-  int token_buffer_size;
+  unsigned int token_buffer_size;
   /* End of the written part of token_buffer. */
   unsigned char *limit;
 
@@ -277,12 +277,12 @@
 #define CPP_OUT_BUFFER(PFILE) ((PFILE)->token_buffer)
 
 /* Number of characters currently in PFILE's output buffer. */
-#define CPP_WRITTEN(PFILE) ((PFILE)->limit - (PFILE)->token_buffer)
+#define CPP_WRITTEN(PFILE) ((size_t)((PFILE)->limit - (PFILE)->token_buffer))
 #define CPP_PWRITTEN(PFILE) ((PFILE)->limit)
 
 /* Make sure PFILE->token_buffer has space for at least N more characters. */
 #define CPP_RESERVE(PFILE, N) \
-  (CPP_WRITTEN (PFILE) + N > (PFILE)->token_buffer_size \
+  (CPP_WRITTEN (PFILE) + (size_t)(N) > (PFILE)->token_buffer_size \
    && (cpp_grow_buffer (PFILE, N), 0))
 
 /* Append string STR (of length N) to PFILE's output buffer.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]