[Bug c/52534] New: gcc doesn't detect incorrect expression in call to va_start
mib.bugzilla at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Mar 8 21:14:00 GMT 2012
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);
^
More information about the Gcc-bugs
mailing list