clang-static-analyzer

Clang: How to get the macro name used for size of a constant size array declaration

邮差的信 提交于 2020-01-14 01:38:32
问题 TL;DR; How to get the macro name used for size of a constant size array declaration, from a callExpr -> arg_0 -> DeclRefExpr. Detailed Problem statement: Recently I started working on a challenge which requires source to source transformation tool for modifying specific function calls with an additional argument. Reasearching about the ways i can acheive introduced me to this amazing toolset Clang. I've been learning how to use different tools provided in libtooling to acheive my goal. But

Omitted code blocks from clang AST for ObjectiveC

随声附和 提交于 2020-01-06 16:18:57
问题 I was generating AST for Objective C code on a .m file The command is roughly like clang-check -ast-dump /source/file.m &> /output/file.txt It had an error that said Error while trying to load a compilation database: Could not auto-detect compilation database for file '/source/file.m' No compilation database found in /source or any parent directory json-compilation-database: Error while opening JSON database: No such file or directory Running without flags. In file included from /source ..

How to set language standard (-std) for Clang static analyzer in Qt Creator

萝らか妹 提交于 2020-01-03 16:47:14
问题 I write my project in C using QtCreator as IDE and CMake for build. QtCreator ver. >= 4.0.0 include Clang static analyzer, that I try to use. In my CMakeLists.txt set: set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}") When I launch analysis in console get errors: error: invalid argument '-std=gnu++11' not allowed with 'C/ObjC' How to pass '-std=gnu99' to clang analyzer? Maybe it's hardcoded in QtCreator plugin sources? UDP1 : Seems like it's the QtCreator bug: https://bugreports.qt.io/browse

Why are static analysis tools missing this seemingly obvious case?

大兔子大兔子 提交于 2020-01-02 05:48:28
问题 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

How can I enable clang-tidy's “modernize” checks?

假如想象 提交于 2019-12-21 11:33:12
问题 I just installed ClangOnWin,and I'm trying to get clang-tidy 's "modernize" checks to work. Unfortunately, clang-tidy doesn't seem to know about them: clang-tidy -list-checks foo.cpp -- | grep modernize produces no output. The "modernize" checks are listed here, but that page seems to document Clang 3.8, and the version I have installed is 3.7. However, version 3.7 is the current one listed at the LLVM Download Page. clang-tidy knows about a variety of security checks, so I think I have it

Clang analyzer missing memory leaks

北战南征 提交于 2019-12-13 03:06:22
问题 I have issue while running clang on an android service on some cpp file. I am creating an intentional memory leak by calling an object instance from another class without deleting it to see if clang creates memory leak warning or not but for some cases It is not creating memory leak warning. 1- If I put a class declaration in same header file with the class that I wanted to create a memory leak, clang catching the memory leak as the following: Example.h class Ad { public: void xx(); }; class

Xcode 3.2: Build & Analyze never finds any issues

我只是一个虾纸丫 提交于 2019-12-12 17:02:22
问题 I've used the Clang Static Analyzer from the command line before. I wanted to try Xcode's built-in version via Build & Analyze. I never get any negative results even though i specially prepared my code with very obvious issues Clang was always able to point out: // over-releasing an object: [label release]; [label release]; // uninitialized vars, allocating but not freeing an object NSString* str; int number; CCLabel* newLabel = [[CCLabel alloc] initWithString:str fontName:str fontSize:number

Is `clang-check` failing to honor `-isystem`?

二次信任 提交于 2019-12-08 02:55:41
问题 For both Clang and GCC, the -isystem flag adds a "system" include path, which causes the compiler not to emit warnings related to code found in those headers. However, running clang-check on my code, I see the following warning: In file included from <myfile>.cpp:1: In file included from <Qt-path>/gcc_64/include/QtCore/QCoreApplication:1: In file included from <Qt-path>/gcc_64/include/QtCore/qcoreapplication.h:40: <Qt-path>/gcc_64/include/QtCore/qobject.h:235:16: warning: Potential memory

How can I count number of times an overloaded operator was used in a code base with particular type of operands

柔情痞子 提交于 2019-12-07 18:16:52
问题 I have a templated class SafeInt<T> (By Microsoft). This class in theory can be used in place of a POD integer type and can detect any integer overflows during arithmetic operations. For this class I wrote some custom templatized overloaded arithmetic operator (+, -, *, /) functions whose both arguments are objects of SafeInt<T> . I typedef'd all my integer types to SafeInt class type. I want to search my codebase for instances of the said binary operators where both operands are of type

silence a compiler warning about releasing a CGMutablePathRef object

旧城冷巷雨未停 提交于 2019-12-07 10:20:19
问题 I have enabled the static analyzer, but it is telling me that at the end of that execution path that object didn't get released, hence possibly causing a memory leak. I am however passing that reference to the created object to another class which will release it. I was wondering if there is a method or keyword to tell the compiled that I will release this object later. I am looking for something like the auto-release. By the way, I am using ARC. I create the object like this: