off-by-one in get_ident

Gabriel Dos Reis gdr@integrable-solutions.net
Tue Dec 13 19:42:00 GMT 2005


Hi, 

Consider this from c-pch.c:

   #define IDENT_LENGTH 8

[...]

   /* Compute an appropriate 8-byte magic number for the PCH file, so that
      utilities like file(1) can identify it, and so that GCC can quickly
      ignore non-PCH files and PCH files that are of a completely different
      format.  */

   static const char *
   get_ident (void)
   {
     static char result[IDENT_LENGTH];
     static const char template[IDENT_LENGTH] = "gpch.013";

The initializer for template is longer (9 characters) than the
requested length for template.  It is mostly harmless in the
surrounding code, but it breaks compilation with C++ compilers.  Which
of the following fix do you prefer

     static const char template[] = "gpch.013";

or

     static const char template[IDENT_LENGTH] 
               = {'g', 'p', 'c', 'h', '.', '0', '1', '3'};

or
?

-- Gaby



More information about the Gcc-patches mailing list