Click on image to see enlargment

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

            bug579.cpp

1    #include <stdio.h>
2
3    void print_out( char n, ... )
4        {
5        if( n == 'i' )
6            printf( "%d", *(int *)(&n + 1) );
7        else if( n == 's' )
8            printf( "%s", *(char **)(&n + 1) );
9        }
10
11   int main()
12       {
13       print_out( 's', "June hath " );
14       print_out( 'i', 30 );
15       print_out( 's', " days.\n" );
16       return 0;
17       }

Our programmer is printing a message using a function with a variable argument list but something is going awry. Can you spot the problem?


bug579.cpp lint Output

--- Module:   bug579.cpp
                        _
void print_out( char n, ... )
bug579.cpp(3) : Warning 579: parameter preceding ellipsis has invalid type
                                        _
        printf( "%d", *(int *)(&n + 1) );
bug579.cpp(6) : Info 826: Suspicious pointer-to-pointer conversion (area too small)
                                          _
        printf( "%s", *(char **)(&n + 1) );
bug579.cpp(8) : Info 826: Suspicious pointer-to-pointer conversion (area too small)

Reference Manual Explanation

  
579   parameter preceding ellipsis has invalid type  -- When an ellipsis is used, the type 
      preceding the ellipsis should not be a type that would undergo a default promotion such 
      as char, short or float.  The reason is that many compilers' variable argument schemes 
      (using stdarg.h) will break down.

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

Previous Bug - Bug #802 - May 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.