This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/52534] New: gcc doesn't detect incorrect expression in call to va_start
- From: "mib.bugzilla at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 08 Mar 2012 21:14:37 +0000
- Subject: [Bug c/52534] New: gcc doesn't detect incorrect expression in call to va_start
- Auto-submitted: auto-generated
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);
^