Sign in to follow this  

Buffer too small assertion failure at object construction

This topic is 824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I have an object who's constructor takes 2 arguments(of custom types too). When the creation of that objects takes place, I receive the following :

 

Debug Assertion Failed

File: f:dd\vctools\crt\crtw32\stdio\vsprintf.c

Expression: ("Buffer too small",0)

 

 

I tried to step through the code, and get into the actual constructor. But it's simply impossible, apparently this assertion failure takes place before entering the actual constructor.

 

Anyone have any idea what the issue might be?

Share this post


Link to post
Share on other sites

When you hit that debug assertion look at your call stack.  Look for the function calling one of the printf family of functions. That will show you where in your code the function is being triggered.

 

 

Again, look at the call stack when the debug assertion triggers.  That is the key to understanding this one.

 

The assertion comes from one of Microsoft's debug checks they added to protect you from your own errors.  

 

The snprintf (and a few other printf variants) takes a length parameter for storing a string. If the contents to be written exceed that length the resulting string is not terminated. Since many programmers have the bad habit of not checking the return values from snprintf and others in that family, the condition would trigger bad behavior in most normal situations. The programmer would use the buffer expecting it to have a properly terminated string, but it isn't terminated, so you likely will display whatever happens to follow it in memory until it comes across a 0 value.

Share this post


Link to post
Share on other sites

I removed the initialization list and i was able to get into the constructor to get to the faulty line. Yes it was string related indeed. Thank you for the input guys.

Share this post


Link to post
Share on other sites

This topic is 824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this