[patch] fix memory corruption in libcpp (pr 19077)

Eric Christopher echristo@redhat.com
Wed Feb 16 04:52:00 GMT 2005


> a couple lines above.  I see that this neglects to handle
> CPP_MACRO_ARG tokens with preceding whitespace.  So your fix is
> correct, but incomplete.  Would you please take out that +1 and
> comment, and retest?

Still no regressions.

OK?

-eric

2005-02-14  Eric Christopher  <echristo@redhat.com>

	PR preprocessor/19077
	* macro.c (cpp_macro_definition): Move handling of whitespace
	to PREV_WHITE conditional. Remove overloading of len
	variable.

Index: macro.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/macro.c,v
retrieving revision 1.8
diff -u -p -w -r1.8 macro.c
--- macro.c	14 Feb 2005 14:43:56 -0000	1.8
+++ macro.c	15 Feb 2005 21:57:40 -0000
@@ -1666,6 +1666,7 @@ cpp_macro_definition (cpp_reader *pfile,
 	len += NODE_LEN (macro->params[i]) + 1; /* "," */
     }
 
+  /* This should match below where we fill in the buffer.  */
   if (CPP_OPTION (pfile, traditional))
     len += _cpp_replacement_text_len (macro);
   else
@@ -1677,11 +1678,14 @@ cpp_macro_definition (cpp_reader *pfile,
 	  if (token->type == CPP_MACRO_ARG)
 	    len += NODE_LEN (macro->params[token->val.arg_no - 1]);
 	  else
-	    len += cpp_token_len (token) + 1; /* Includes room for ' '.  */
+	    len += cpp_token_len (token);
+
 	  if (token->flags & STRINGIFY_ARG)
 	    len++;			/* "#" */
 	  if (token->flags & PASTE_LEFT)
 	    len += 3;		/* " ##" */
+	  if (token->flags & PREV_WHITE)
+	    len++;              /* " " */
 	}
     }
 
@@ -1741,10 +1745,10 @@ cpp_macro_definition (cpp_reader *pfile,
 
 	  if (token->type == CPP_MACRO_ARG)
 	    {
-	      len = NODE_LEN (macro->params[token->val.arg_no - 1]);
 	      memcpy (buffer,
-		      NODE_NAME (macro->params[token->val.arg_no - 1]), len);
-	      buffer += len;
+		      NODE_NAME (macro->params[token->val.arg_no - 1]),
+		      NODE_LEN (macro->params[token->val.arg_no - 1]));
+	      buffer += NODE_LEN (macro->params[token->val.arg_no - 1]);
 	    }
 	  else
 	    buffer = cpp_spell_token (pfile, token, buffer);




More information about the Gcc-patches mailing list