Re: vsprintf crashes
Re: vsprintf crashes
- Subject: Re: vsprintf crashes
- From: Dmitry Markman <email@hidden>
- Date: Fri, 21 Apr 2006 22:04:58 -0400
I'm just curious
why you have to do that manipulation:
strcpy(buffer + vsprintf(buffer,format,args), "");
vsprintf will put in the buffer c string anyway, so no need for
that cumbersome statement
strcpy(buffer + vsprintf(buffer,format,args), "");
vsprintf(buffer,format,args) would be enough
did I miss something?
also as vsprintf man page advices
it's much safer to use vsnprintf variant
vsprintf(buffer,sizeof(buffer),format,args)
so even if buffer isn't enough vsnprintf will cut resulting string
properly and will put 0 at the end of the buffer
from man page:
The snprintf() and vsnprintf() functions will write at most size-1 of
the
characters printed into the output string (the size'th
character then
gets the terminating `\0');
On Apr 21, 2006, at 8:45 PM, Alfred Van Hoek wrote:
Could someone enlighten me why the following crashes in my dylib?
It used to work with the previous version of Xcode, and works ok on
windows:
void dlog(char *format, ...)
{
va_list args;
char buffer[255];
va_start(args,format);
strcpy(buffer + vsprintf(buffer,format,args), "");
Str255 dst;
CopyC2P(buffer, dst);
#ifndef WIN32
DebugStr(dst);
#else
OutputDebugString(buffer);
#endif
va_end(args);
}
Thread 0 Crashed:
0 libSystem.B.dylib 0x90002f48 strlen + 8
1 libSystem.B.dylib 0x90011d7c __vfprintf + 5768
2 libSystem.B.dylib 0x90031d20 vsprintf + 224
3 My.dylib 0x0101a964 dlog + 44 (DConPrefix.cpp:200)
Alfred
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Dmitry Markman
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden