This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/52534] New: gcc doesn't detect incorrect expression in call to va_start


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52534

             Bug #: 52534
           Summary: gcc doesn't detect incorrect expression in call to
                    va_start
    Classification: Unclassified
           Product: gcc
           Version: 4.5.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mib.bugzilla@gmail.com


The C standard is very clear that the second argument to va_start is a
parameter identifier, not an expression. 

For example,

int maxof(int, ...) ;
void f(void);

int maxof(int n_args, ...){
    register int i;
    int max, a;
    va_list ap;
    va_start(ap, (unsigned int)n_args);
    max = va_arg(ap, int);
    for(i = 2; i <= n_args; i++) {
       if((a = va_arg(ap, int)) > max) max = a;
    }
    va_end(ap);
    return max;
}

Intel compiler finds the bug:
vaarg.c(12): error: incorrect use of va_start
      va_start(ap, (unsigned int)n_args);
      ^


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]