• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: vsprintf crashes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >vsprintf crashes (From: Alfred Van Hoek <email@hidden>)

  • Prev by Date: Re: vsprintf crashes
  • Next by Date: Re: Pre-binding disabled because of overlap - WTF?
  • Previous by thread: Re: vsprintf crashes
  • Next by thread: Re: Xcode-users Digest, Vol 3, Issue 297
  • Index(es):
    • Date
    • Thread