PVS-StudioWarnings

PVS-Studio warning V557 for LibLog

Nov 12th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. typedef struct LogState {
  2.   int     fakeFd;
  3.   char   *debugName;
  4.   int     isBinary;
  5.   ....
  6. } LogState;
  7.  
  8. #define MAX_OPEN_LOGS 16
  9.  
  10. static LogState *openLogTable[MAX_OPEN_LOGS];
  11.  
  12. static LogState *createLogState()
  13. {
  14.   size_t i;
  15.  
  16.   for (i = 0; i < sizeof(openLogTable); i++) {
  17.     if (openLogTable[i] == NULL) {
  18.       openLogTable[i] = calloc(1, sizeof(LogState));
  19.       openLogTable[i]->fakeFd = FAKE_FD_BASE + i;
  20.       return openLogTable[i];
  21.     }
  22.   }
  23.   return NULL;
  24. }
  25.  
  26. This is what should have been written here: sizeof(openLogTable) / sizeof(openLogTable[0]).
  27.  
  28.  
  29. This suspicious code was found in LibLog project by PVS-Studio static code analyzer.
  30. Warning message is:
  31. V557 Array overrun is possible. The value of 'i' index could reach 63. fake_log_device.c 153
  32.  
  33. 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