PVS-StudioWarnings

PVS-Studio warning V547 for DOSBox

Nov 12th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. void SERIAL_getErrorString(char* buffer, int length) {
  2.   ...
  3.   if((length - sysmsg_offset -
  4.       strlen((const char*)sysmessagebuffer)) >= 0)
  5.      memcpy(buffer + sysmsg_offset, sysmessagebuffer,
  6.             strlen((const char*)sysmessagebuffer));
  7.   ...
  8. }
  9.  
  10. This is an example of unsafe code from the viewpoint of buffer overflows. The strlen() function returns size_t. It means that the check for buffer overflow doesn't work.
  11.  
  12. This suspicious code was found in DOSBox project by PVS-Studio static code analyzer.
  13. Warning message is:
  14. V547 Expression is always true. Unsigned type value is always >= 0. dosbox libserial.cpp 155
  15.  
  16. 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