Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LONG GetRegKey (HKEY key, LPCTSTR subkey, LPTSTR retdata)
- {
- HKEY hkey;
- LONG retval = ::RegOpenKeyEx (key, subkey,
- 0, KEY_QUERY_VALUE, &hkey);
- if (retval == ERROR_SUCCESS)
- {
- long datasize = MAX_PATH;
- TCHAR data[MAX_PATH];
- ::RegQueryValue (hkey, NULL, data, &datasize);
- // Cause C4996 warning, marked as deprecation candidate
- // _tcscpy (retdata, data);
- // Safe replacement
- strcpy_s(retdata, sizeof(retdata), data );
- ::RegCloseKey (hkey);
- }
- return retval;
- }
- It was right but unsafe. Then they made it safe but not right :)
- This suspicious code was found in CamStudio project by PVS-Studio static code analyzer.
- Warning message is:
- V579 The strcpy_s function receives the pointer and its size as arguments. It is possibly a mistake. Inspect the second argument. camsys.cpp 39
- PVS-Studio is a static analyzer for detecting bugs in the source code of applications written in C, C++, C++11, C++/CX. Site: http://www.viva64.com/en/pvs-studio/
Advertisement
Add Comment
Please, Sign In to add comment