Click on image to see enlargment

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

            bug786.c


1    #include <stdio.h>
2    #include <stdlib.h>
3
4    const char *flowers[] =
5        {
6        "rose", "tulip", "daisy"
7        "petunia", "orchid", "lily"
8        };
9
10   int main()
11       {
12       int i;
13       int choice;
14
15       for( i = 0; i < 25; i++ )
16           {
17           choice = rand() % 6;
18           printf( "%s\n", flowers[choice] );
19           }
20       return 0;
21       }

A florist (of questionable taste) sets up a program to produce a Valentine's Day Special Random Bouquet. Upon running the program he was told that it had "encountered a problem and needs to close". Can you find the problem?


bug786.c lint Output

--- Module:   bug786.c (C)
    _
    "petunia", "orchid", "lily"
bug786.c(7) : Info 786: String concatenation within initializer

Reference Manual Explanation


786    String concatenation within initializer  -- Although it is
       perfectly 'legal' to concatenate string constants within an
       initializer, this is a frequent source of error.  Consider:

               char *s[] = { "abc" "def" };

       Did the programmer intend to have an array of two strings but
       forget the comma separator?  Or was a single string intended?


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


Previous Bug - Bug #1567 - January 2011

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 2011, Gimpel Software, All rights reserved.