When we pass arg which is of type va_list as a parameter to a different function which calls vsprintf and vfprint giving one of the parameter as args, It gives core dump. But when we make a copy (i.e va_copy) and pass copy to one of vsprintf or vfprintf and args to other it work fines.
This happens in 64 bit compiler and works fine with 32 bit compiler.
Can anyone explain be the reason?
For example below code will cause core dump

func(int a, char *preBuf,va_list arg)
{
// Initialization and memory allocation Code
    len = vfprintf (file,preBuf,arg);
// Some code
    vsprintf (file,preBuf,arg);
// Other part of Code
}

And if we use va_copy it works fine.
For example if below changes are made it works fine.

func(int a, char *preBuf,va_list arg)
{
// Initialization and memory allocation Code
va_copy (copy , arg);
len = vfprintf (file,preBuf,copy);
// Some code
vsprintf (file,preBuf,arg);
// Other part of Code
}

Can you give us a working minimal program that demonstrates the problem?

From the man pages:

   int vfprintf(FILE *stream, const char *format, va_list ap);
   int vsprintf(char *str, const char *format, va_list ap);

The two functions take differenet argument types for the first argument. I don't know what file is in your example but it certainly can not be pointer to both a FILE and char at the same time. My guess is that you are ignoring compiler warnings and the fact that it seems to work on a 32-bit system is simply luck.

Perhaps providing a full example of your code would help us investigate further.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.