Click on image to see enlargment

PC-lint/FlexeLint Output | Reference Manual Explanation | Home


1    #include <stdio.h>
2    #include <string.h>
4    const char * const eof = "\0xFF";
5    char list[2000] = {0};
7    void append( const char *flower )
8        {
9        strcat( list, flower );
10       strcat( list, eof );
11       }
12   int main()
13       {
14       const char *next;
15       append( "Calla Lily" );
16       append( "Daisy" );
17       append( "Tulip" );
18       next = strchr( list, 0xFF );
19       if( !next ) printf( "Huh?\n" );
20       }

A florist is beginning to write a program to prepare lists of flowers. The names of the flowers are to be separated by a byte of all ones. But something is not working. To his amazement this test program is printing 'Huh?'. What's wrong?

bug693.cpp lint Output

--- Module:   bug693.cpp (C++)
const char * const eof = "\0xFF";
bug693.cpp(4) : Warning 693: Hexadecimal digit 'F' immediately after '\0x' is
    suspicious in string literal
bug693.cpp(4) : Info 840: Use of nul character in a string literal

Reference Manual Explanation

693    Hexadecimal digit 'Char' immediately after 'String' is suspicious in
       string literal.  -- A String was found that looks suspiciously like
       (but is not) a hexadecimal escape sequence; rather, it is a null character
       followed by letter "x" followed by some hexadecimal digit, e.g.:


       was found where the programmer probably meant to type "\x62".  If you need
       precisely this sequence you can use:

                 "\0" "x62"

       and this warning will not be issued.

If you have comments or questions about this bug, please post them to our   Discussion Forum

Previous Bug - Bug #1572 - April 2009

Use our Interactive Demo to Run FlexeLint on our Bugs of the Month

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2009, Gimpel Software, All rights reserved.