__inline int my_sprintf (char *dest,char *format,...)
{
va_list va;
va_start(va,format);
return vsprintf(dest,format,va);
}
My issue is that I can't add the buffer size parameter to my_sprintf because it's used in more than 50k places, this I can't replace vsprintf with vsprintf_s or vsnprintf.
any alternative to make the above function safer ?
What you're asking here is a specialization of the (in)famous question: "how to get the size of an array if all I have is a pointer?"
There's no way to figure out what's the size of the object pointed to by
dest
. Your best option is likely to bite the bullet and change those 50k places to pass the size.There might be more to your code that you're not telling us. For example, in those "50k" places that you mention, is the size known? If so you could get away with a dirty variadic macro that uses
sizeof
behind the scenes and then calls a function that takes a length parameter.