cpp token_buffer not being NULL terminated causes fixproto bugs

Zack Weinberg zack@wolery.cumb.org
Fri Apr 28 13:17:00 GMT 2000

On Fri, Apr 28, 2000 at 12:51:25PM -0700, Jason Merrill wrote:
> Why aren't we NULL-terminating names anymore?

Consistency.  It's easier to say "nothing is NULL-terminated" than
"nothing is NULL-terminated except [...]".

> I specifically didn't change
> that because of code that wants to use strcmp.  Using strncmp is wrong for
> these cases, since the test will also match, say, "inlineasnotehu!!".
> It might be appropriate to write a new macro which would test the length of
> the token, do a strncmp and then test that the next character in the other
> string is NULL.

This is a good idea.  There is enough logic involved that it should be
an entire function:

/* Compares, in the manner of strcmp(3), the token beginning at TOKEN
   and extending for LEN characters to the NUL-terminated string
   STRING.  Typical usage:

   if (! cpp_idcmp (pfile->token_buffer + here, CPP_WRITTEN (pfile) - here,
     { ... }

cpp_idcmp (token, limit, string)
    const U_CHAR *token;
    size_t len;
    const char *string;
  size_t len2 = strlen (string);
  int r;

  if (r = memcmp (token, string, MIN (len, len2)))
    return r;

  /* The longer of the two strings sorts after the shorter.  */
  if (len == len2)
    return 0;
  else if (len < len2)
    return -1;
   return 1;

Kaveh, does this look usable to you?  If so, I'll take care of fixing
scan-decls.c. and fix-header.c.  It may be awhile, I'm halfway through
a messy glue operation.


More information about the Gcc-patches mailing list