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
}