Dave's Brain

Browse - programming tips - snprintf s crashes

Date: 2010mar17

Q.  How do I use _snprintf_s() and why is it crashing?

A.  The regular way to is it is:

	char	buf[1000];

	_snprintf_s(buf, sizeof(buf), _TRUNCATE, ...);

But this crashes

More info:
http://connect.microsoft.com/VisualStudio/feedback/details/289013/snprintf-s-causes-array-out-of-bounds-write-when-the-truncate-flag-is-used-for-count

So modify your stdlib.h file as explained there or use _snprintf() like this:

	_snprintf(buf, sizeof(buf), ...);
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: