Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LRESULT CALLBACK CMainWindow::WinMsgHandler(....)
- {
- ...
- if (pNMHDR->code == TTN_GETDISPINFO)
- {
- LPTOOLTIPTEXT lpttt;
- lpttt = (LPTOOLTIPTEXT) lParam;
- lpttt->hinst = hResource;
- // Specify the resource identifier of the
- // descriptive text for the given button.
- TCHAR stringbuf[MAX_PATH] = {0};
- ...
- lpttt->lpszText = stringbuf;
- }
- ...
- }
- It's not that simple with this code. Theoretically, the code contains an error. Practically, it works well.
- The V507 diagnostic message warns you that an object is used after being destroyed. The 'stringbuf' buffer will be used after exiting the body of the 'if' operator.
- If 'stringbuf' was an object of the class std::string, for instance, its behavior would be incorrect. We would use an already destroyed object in that case. But here 'stringbuf' is an array created in the stack. The Visual C++ compiler doesn't use this stack area again, so the buffer will exist until the 'CMainWindow::WinMsgHandler' function finishes its work. Thus, no error occurs, although the code is potentially dangerous.
- This suspicious code was found in TortoiseSVN project by PVS-Studio static code analyzer.
- Warning message is:
- V507 Pointer to local array 'stringbuf' is stored outside the scope of this array. Such a pointer will become invalid. mainwindow.cpp 277
- 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
Advertisement