Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 816809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:53:45+00:00 2026-05-15T01:53:45+00:00

I have the following function from some legacy code that I am maintaining. long

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:53:45+00:00Added an answer on May 15, 2026 at 1:53 am

    As written, when you pass in only one myStruct argument, s1 is bound to that argument and your va_list will be empty. Then, the first thing you do in the loop is to get the argument from that empty list, hence the NULL.

    If you require at least one argument and want the compiler to type-check that for you, you’d have to do something like this:

    long getMaxStart(long start, long count, const myStruct *s1, ...) {
        ...
        va_start(marker, s1);
        maxstart = s1->firstvalid; /* actually use s1 this time! */
        for (i1 = 1; i1 < count; i1++) /* different from your code */
        {
            ...
        }
        ...
    }
    

    Otherwise, you’re better off just removing s1 from the function definition like Potatoswatter mentioned:

    long getMaxStart(long start, long count, ...) {
        ...
        va_start(marker, count); /* not a bug */
        maxstart = -1; /* pick something resonable for your app */
        for (i1 = 0; i1 < count; i1++)
        { 
            ...
        }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 417k
  • Answers 417k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I had this problem too. The solution is to never… May 15, 2026 at 9:48 am
  • Editorial Team
    Editorial Team added an answer Lots of these properties are specified in the javadocs for… May 15, 2026 at 9:48 am
  • Editorial Team
    Editorial Team added an answer Try explicitly set the locale to UTF-8. setlocale(LC_CTYPE, "UTF-8"); ...… May 15, 2026 at 9:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.