Click on image to see enlargment

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

            bug802.cpp

1    #include <stdio.h>
2    #include <string.h>
3    #include <stdlib.h>
4
5    #define N 5
6    const char *a[N] = { "rose", "aster", "tulip", "daisy", "lilac" };
7  
8    char *select( int low, int high ) {
9        const char *s = NULL;
10       static char flower[100];
11       strcpy( flower, "least flower in range is " );
12       if( high > N ) high = N;
13       for( int i = low; i < high; i++ )
14           { if( !s || strcmp(a[i],s) < 0 ) s = a[i]; }
15       strcat( flower, s );
16       return flower;
17   }
18   int main( int argc, const char * const *argv ) {
19       if( argc >= 2 )
20           printf( " %s\n", select( atoi(argv[1]), atoi(argv[2]) ) );
21       return 0;
22   }

This program prints the least flower (in alphabetic order) from a range of indices. The programmer thought he had taken care of things well enough to avoid the dreaded Illegal Operation but overlooked one little thing.


bug802.cpp lint Output

--- Module:   bug802.cpp
                      _
   strcat( flower, s );
bug802.cpp(15) : Info 802: Conceivably passing a null pointer to function
    'strcat(char *, const char *)', arg. no. 2 [Reference: file bug802.cpp: line 9]

Reference Manual Explanation

  
802   Conceivably passing a null pointer to function 'Symbol', Context Reference  -- A NULL
      pointer is conceivably being passed to a function identified by Symbol.  The argument in 
      question is given by Context.  The function is either a library function designed not to 
      receive a NULL pointer or a user function dubbed so via the option -function.  

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

Previous Bug - Bug #1561 - April 2004

[ new ] 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 2006, Gimpel Software, All rights reserved.