Problems with variadic function
Posted
by morpheous
on Stack Overflow
See other posts from Stack Overflow
or by morpheous
Published on 2010-05-28T00:45:07Z
Indexed on
2010/05/28
1:51 UTC
Read the original article
Hit count: 236
I have the following function from some legacy code that I am maintaining.
long getMaxStart(long start, long count, const myStruct *s1, ...)
{
long i1, maxstart;
myStruct *s2;
va_list marker;
maxstart = start;
/*BUGFIX: 003 */
/*(va_start(marker, count);*/
va_start(marker, s1);
for (i1 = 1; i1 <= count; i1++)
{
s2 = va_arg(marker, myStruct *); /* <- s2 is assigned null here */
maxstart = MAX(maxstart, s2->firstvalid); /* <- SEGV here */
}
va_end(marker);
return (maxstart);
}
When the function is called with only one myStruct argument, it causes a SEGV. The code compiled and run without crashing on Windows XP when I compiled it using VS2005. I have now moved the code to Ubuntu Karmic and I am having problems with the stricter compiler on Linux. Is anyone able to spot what is causing the parameter not to be read correctly in the var_arg() statement?
I am compiling using gcc version 4.4.1
Edit
The statement that causes the SEGV is this one:
start = getMaxStart(start, 1, ms1);
The variables 'start' and 'ms1' have valid values when the code execution first reaches this line.
© Stack Overflow or respective owner