Skip to main content
gamedev.net
🔒 Locked

Stack around variable was corrupted

Started by roquero Mar 25, 2006 at 3:14 AM 1 replies 1.1k views
Original Post
roquero
roquero
I have written this simple test code: It's a Win32 Console Application with support for MFC. -------------------8<---------------------- #include "stdafx.h" #include 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
/roqhttp://roq.blogspot.com
roquero
roquero
Aha, the numChars-parameter is used for both in and out.

Thanks Anonymous Poster!

/roq
/roqhttp://roq.blogspot.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.