cppcheck

being sure about “unknown evaluation order”

醉酒当歌 提交于 2019-12-10 12:28:41
问题 Since version 1.80, Cppcheck tells me that Expression 'msg[ipos++]=checksum(&msg[1],ipos-1)' depends on order of evaluation of side effects in this code sequence (simplified, data is a variable) BYTE msg[MAX_MSG_SIZE]; // msg can be smaller, depending on data encoded int ipos = 0; msg[ipos++] = MSG_START; ipos += encode(&msg[ipos], data); msg[ipos++] = checksum(&msg[1], ipos-1); // <---- Undefined Behaviour? msg[ipos++] = MSG_END; // increment ipos to the actual size of msg and treats this as

Possible null pointer dereference - otherwise it is redundant to check it against null

痴心易碎 提交于 2019-12-10 09:34:33
问题 I have the following code, which is working properly: int result = ERRORCODE_OK; if (dataObj == NULL || dataObj->inputSignal == NULL) { result = ERRORCODE_MISSING_DATAOBJ; } if (result == ERRORCODE_OK && dataObj->spectrum == NULL) // CPP-Check error { result = Calculate(dataObj->inputSignal, .. ); } return result; But CppCheck gives me the following error: Possible null pointer dereference: dataObj - otherwise it is redundant to check it against null. I don't understand why. If the dataobj is

How could reading numbers using sscanf crash?

隐身守侯 提交于 2019-12-10 01:36:40
问题 Cppcheck has detected a potential problem in a code like this: float a, b, c; int count = sscanf(data, "%f,%f,%f", &a, &b, &c); It says that: "scanf without field width limits can crash with huge data". How is that possible? Is that a known bug in some sscanf implementations? I understand that the numbers may overflow (numerically), but how could the program crash? Is that a false positive in cppcheck? I have found a similar question: scanf Cppcheck warning, but the answer is not completely

Cppcheck Possible null pointer dereference:

ぐ巨炮叔叔 提交于 2019-12-08 14:24:17
问题 i am just using cppcheck the code is working properly just cppcheck gives this errors. void WorkerThread(WorkBuffer* m_buffer) { std::cout << "Thread : " << m_buffer->m_id << ".....Starting" << std::endl; if (NULL == m_buffer) std::cout << "Thread : " << m_buffer->m_id << "......work buffer is null" << std::endl; while(!shut_down_flag) { int k = 0; //Sleep(1); SleepSystemUsec(100000); std::cout << "Thread : " << m_buffer->m_id << "....in while loop" << std::endl; } // of while(!shut_down_flag

clang-tidy cmake exclude file from check

▼魔方 西西 提交于 2019-12-07 12:03:26
问题 I have a dependency as source in my project that I have no control over. I'm using cmake's clang-tidy integration to analyze my code, and this dependency is firing A LOT of warnings. Is there a way to tell cmake not to run clang-tidy on specific files ? I tried to add the files to the -line-filter option of clang-tidy, but this doesn't work: set_target_properties(target PROPERTIES CXX_CLANG_TIDY "${clang_tidy_loc};\ ${TIDY_CONFIG} \ -line-filter=\"[\ {\"name\":\"path/to/file.cpp\"},\ {\"name\

Can I include cppcheck suppression within a function header?

房东的猫 提交于 2019-12-06 04:36:32
问题 I have added an inline comment to suppress a cppcheck unusedFunction warning for a function, but I would like to include this within the function header so that Doxygen can document all of the unused functions (I am implementing an API, so I have many functions that will not be used in my source). I would prefer not to suppress all unusedFunction errors, but rather on a per-function basis. I would like to do something like this: /** * API function description * * @param p1 function pointer to

clang-tidy cmake exclude file from check

故事扮演 提交于 2019-12-05 20:33:09
I have a dependency as source in my project that I have no control over. I'm using cmake's clang-tidy integration to analyze my code, and this dependency is firing A LOT of warnings. Is there a way to tell cmake not to run clang-tidy on specific files ? I tried to add the files to the -line-filter option of clang-tidy, but this doesn't work: set_target_properties(target PROPERTIES CXX_CLANG_TIDY "${clang_tidy_loc};\ ${TIDY_CONFIG} \ -line-filter=\"[\ {\"name\":\"path/to/file.cpp\"},\ {\"name\":\"path/to/file.h\"}\ ]\"") If the solution could work with other static analyzers like cppcheck it

Why are static analysis tools missing this seemingly obvious case?

ⅰ亾dé卋堺 提交于 2019-12-05 14:28:17
I have a very simple C program with a potential buffer overflow using strcpy : #include <string.h> #include <stdio.h> void buffer_overflow(char* dst, const char* src) { strcpy(dst, src); } int main(int argc, char** argv) { if(argc == 2) { char buffer[16] = {0}; buffer_overflow(buffer, argv[1]); printf("[%d]: %s", (int)strlen(buffer), buffer); } return 0; } Neither clang static analyzer (using scan-build gcc -O0 -g3 -gdwarf-2 ) nor cppcheck (using cppcheck --enable=warning,style ) find this as an issue. Am I just asking too much from my static analysis tools? I can't speak for the quality of

How could reading numbers using sscanf crash?

那年仲夏 提交于 2019-12-05 00:52:22
Cppcheck has detected a potential problem in a code like this: float a, b, c; int count = sscanf(data, "%f,%f,%f", &a, &b, &c); It says that: "scanf without field width limits can crash with huge data". How is that possible? Is that a known bug in some sscanf implementations? I understand that the numbers may overflow (numerically), but how could the program crash? Is that a false positive in cppcheck? I have found a similar question: scanf Cppcheck warning , but the answer is not completely satisfying. The answer mentions type safety, but that should not be an issue here. I am a Cppcheck

scanf Cppcheck warning

别说谁变了你拦得住时间么 提交于 2019-12-04 03:13:18
问题 Cppcheck shows the following warning for scanf: Message: scanf without field width limits can crash with huge input data. To fix this error message add a field width specifier: %s => %20s %i => %3i Sample program that can crash: #include int main() { int a; scanf("%i", &a); return 0; } To make it crash: perl -e 'print "5"x2100000' | ./a.out I cannot crash this program typing "huge input data". What exactly should I type to get this crash? I also don't understand the meaning of the last line