Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / buffer overrun?

Author
Message
Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 2nd Feb 2010 09:12
okay ive been getting this annoying buffer overrun error that has started ever since i started using a sprinf in my code but i dont know how to fix this also i have tried replacing the sprintf command and the program runs fine so im sure that sprintf is the problem.

could someone please look at the code and tell me what ive done wrong this time.

Attachments

Login to view attachments
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 2nd Feb 2010 16:00
Have you tried replacing the %i with %d?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 2nd Feb 2010 18:55
yes i already tried %d, acctually the code was originally %d but i read a forum that said to change it but either way the error still occurs
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 2nd Feb 2010 19:06
Use the amazing debugging features you get in VS? A buffer overrun will halt the execution of the app and if you have the debugger attached then you have the ability to get a stack trace up to the (accessible)erroneous code from which you'll also be able to view all local variables and hopefully see exactly what went wrong. This may not be the case though, depending on what causes the error, you may have to resort to the more cumbersome breakpoint and step-through approach, or the old remove code until it works trick.

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 2nd Feb 2010 19:30
ok but it would helpful if someone could tell me what is the most common ways a sprintf can cause this error when the code exits.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Feb 2010 19:36
Have you commented out the offending code? As otherwise I can't see what would cause the problem. If so, your sprintf_s call is missing its sizeOfBuffer argument.
Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 2nd Feb 2010 19:45
ignore that sprintf_s command and replace it with just sprintf for some reason when i change the code to sprintf from sprintf_s it wont always save the change ill put the code without the sprintf_s below in the download.

also is it possible that my computer is causing the problem since my computer is only single coered and the proccesor reaches 98% when running the code?

Attachments

Login to view attachments
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd Feb 2010 19:35
1) Use sprintf_s not sprintf
2) 98% CPU is normal for DBPro applications which don't call 'Sleep()'
3) Why not try stepping through your code using the debugger!

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 3rd Feb 2010 23:15
ive tried stepping through the code but i could not find anything especially since im not exactly sure what it is that im looking for as this is the only code that ive made that needs to use a sprintf and this code is the first time that ive recieved a buffer overrun. the only thing that i have discovered so far is that this code segment


when removed from the other code will not cause the error but i know that this segment somehow converts the integer Score into a String which is a step neccesary to print the score integer beyond that im unsure of what is happening the only geuss ive got is that more memory needs to be allocated to the string but since ive never used this comand before im not even sure if that is possible.

also im unfamiliar with this code


i know it declares a string but what is the [400] for and is it possible that the number within those brackets needs to changed?
Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 8th Feb 2010 23:37
alright since i couldnt find anything wrong when i used the debugger i tried stepping through the code the hard way by using /* and */ after going through all of the code this way i never once encountered the error and everything still works fine ive restarted my computer and even tried the code on another computer and the error still wont reappear i didnt change any of the code except i put an extra blank line in between a couple code snipets either way im not sure what happened but it works... for now anyway, thanks to all the people who took the time to help.

Login to post a reply

Server time is: 2024-11-20 05:21:45
Your offset time is: 2024-11-20 05:21:45