Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct LogState {
- int fakeFd;
- char *debugName;
- int isBinary;
- ....
- } LogState;
- #define MAX_OPEN_LOGS 16
- static LogState *openLogTable[MAX_OPEN_LOGS];
- static LogState *createLogState()
- {
- size_t i;
- for (i = 0; i < sizeof(openLogTable); i++) {
- if (openLogTable[i] == NULL) {
- openLogTable[i] = calloc(1, sizeof(LogState));
- openLogTable[i]->fakeFd = FAKE_FD_BASE + i;
- return openLogTable[i];
- }
- }
- return NULL;
- }
- This is what should have been written here: sizeof(openLogTable) / sizeof(openLogTable[0]).
- This suspicious code was found in LibLog project by PVS-Studio static code analyzer.
- Warning message is:
- V557 Array overrun is possible. The value of 'i' index could reach 63. fake_log_device.c 153
- 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