Jump to content
  • Advertisement
Sign in to follow this  
roquero

Stack around variable was corrupted

This topic is 4502 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

I have written this simple test code: It's a Win32 Console Application with support for MFC. -------------------8<---------------------- #include "stdafx.h" #include <atlbase.h> int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { CRegKey regKey; regKey.Create(HKEY_CURRENT_USER, _T("SOFTWARE\\Test\\")); regKey.SetStringValue(_T("TestString1"), _T("2006-04-24")); TCHAR strValue[20]; ULONG numChars; regKey.QueryStringValue(_T("TestString1"), strValue, &numChars); _tprintf(_T("%s\n"), strValue); return 0; } -------------------8<---------------------- The String that is stored in registry and read back, "2006-04-24", is 11 chars long (with null), so 20 elements in strValue should be enough. But for some reason I get "Stack around variable 'strValue' was corrupted. I only get this problem with VS2003, but not with VS2005. I can solve the problem by using a variable on the heap with new, but I think this should work. Can you see a problem with my code causing this error? /Roq

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
ULONG numChars = 20;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!