Sign in to follow this  

Stack around variable was corrupted

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

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