From b1280514cabcf5e782a078e4034ca1af6ea48ee8 Mon Sep 17 00:00:00 2001
From: neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 24 Apr 2003 20:03:57 +0000
Subject: [PATCH] 	* cpplex.c (cpp_token_len): Tighten up. 
 (cpp_token_as_text): Need extra byte now. 	* cpplib.c (glue_header_name):
 Need extra 2 bytes. 	* cppmacro.c (cpp_macro_definition): Need extra byte.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@66049 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog  |  7 +++++++
 gcc/cpplex.c   | 14 +++++++-------
 gcc/cpplib.c   |  2 +-
 gcc/cppmacro.c |  2 +-
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 1ae16b22ae76..89ba2f8d2037 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2003-04-24  Neil Booth  <neil@daikokuya.co.uk>
+
+	* cpplex.c (cpp_token_len): Tighten up.
+	(cpp_token_as_text): Need extra byte now.
+	* cpplib.c (glue_header_name): Need extra 2 bytes.
+	* cppmacro.c (cpp_macro_definition): Need extra byte.
+
 2003-04-24  Alexander Kabaev <kan@FreeBSD.ORG>
 
 	* config/sparc/sparc.md (umulsidi3, mulsidi3): Avoid using
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index c9c064143c35..4f0767e42c8e 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -1094,8 +1094,8 @@ _cpp_lex_direct (pfile)
   return result;
 }
 
-/* An upper bound on the number of bytes needed to spell TOKEN,
-   including preceding whitespace.  */
+/* An upper bound on the number of bytes needed to spell TOKEN.
+   Does not include preceding whitespace.  */
 unsigned int
 cpp_token_len (token)
      const cpp_token *token;
@@ -1104,12 +1104,12 @@ cpp_token_len (token)
 
   switch (TOKEN_SPELL (token))
     {
-    default:		len = 0;				break;
+    default:		len = 4;				break;
     case SPELL_LITERAL:	len = token->val.str.len;		break;
     case SPELL_IDENT:	len = NODE_LEN (token->val.node);	break;
     }
-  /* 1 for whitespace, 4 for comment delimiters.  */
-  return len + 5;
+
+  return len;
 }
 
 /* Write the spelling of a token TOKEN to BUFFER.  The buffer must
@@ -1167,8 +1167,8 @@ unsigned char *
 cpp_token_as_text (pfile, token)
      cpp_reader *pfile;
      const cpp_token *token;
-{
-  unsigned int len = cpp_token_len (token);
+{ 
+  unsigned int len = cpp_token_len (token) + 1;
   unsigned char *start = _cpp_unaligned_alloc (pfile, len), *end;
 
   end = cpp_spell_token (pfile, token, start);
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index 9b95ac950cff..271aa5d487b6 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -594,7 +594,7 @@ glue_header_name (pfile)
 	  break;
 	}
 
-      len = cpp_token_len (token);
+      len = cpp_token_len (token) + 2; /* Leading space, terminating \0.  */
       if (total_len + len > capacity)
 	{
 	  capacity = (capacity + len) * 2;
diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c
index b0b10ae92d75..f77f6b368374 100644
--- a/gcc/cppmacro.c
+++ b/gcc/cppmacro.c
@@ -1715,7 +1715,7 @@ cpp_macro_definition (pfile, node)
 	  if (token->type == CPP_MACRO_ARG)
 	    len += NODE_LEN (macro->params[token->val.arg_no - 1]);
 	  else
-	    len += cpp_token_len (token); /* Includes room for ' '.  */
+	    len += cpp_token_len (token) + 1; /* Includes room for ' '.  */
 	  if (token->flags & STRINGIFY_ARG)
 	    len++;			/* "#" */
 	  if (token->flags & PASTE_LEFT)
-- 
GitLab