Problems with variadic function (C)
        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
            0:51 UTC
        
        
        Read the original article
        Hit count: 250
        
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 an 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
© Stack Overflow or respective owner