clang-static-analyzer

Clang Error on “Potential null dereference.”

这一生的挚爱 提交于 2019-12-03 05:30:41
问题 I keep getting Clang errors on the following type of code and I can't figure out why they're erroneous or how to resolve them to Clang's satisfaction: + (NSString *)checkForLength: (NSString *)theString error: (NSError **)error { BOOL hasLength = ([theString length] > 0); if (hasLength) return theString; else { *error = [NSError errorWithDomain:@"ErrorDomain" code:hasLength userInfo:nil]; return nil; } } Leaving aside the utterly-contrived nature of the example (which Clang did object to so

Using an external Xcode Clang Static Analyzer binary, with additional checks

旧城冷巷雨未停 提交于 2019-12-03 03:59:37
I’m using Xcode 3.2.4 and have setup the Clang Static Analyser feature to use a newer build of the binary, as detailed here: http://clang-analyzer.llvm.org/xcode.html (Basically using the set-xcode-analyzer command line utility to change which copy of the Static Analyser that Xcode uses for Build and Analyze .) What I can’t figure is how to set that binary to use additional checks, such as -analyzer-check-objc-missing-dealloc when using the binary via Xcode, as detailed here: http://loufranco.com/blog/files/scan-build-better-than-build-analyze.html and in scan-build --help. AVAILABLE ANALYSES

How to make the Clang Static Analyzer output its working from command line?

半世苍凉 提交于 2019-12-02 18:21:33
I'm running Clang 3.4 on Ubuntu 12.10 (from http://llvm.org/apt/ ). I ran the analyzer (clang --analyze) over some code, and it found a couple of issues: Blah.C:429:9: warning: Declared variable-length array (VLA) has zero size unsigned char separatedData[groupDataLength]; ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ But the specific issue isn't important. I want to know the steps of how it came to that conclusion (the code is complex enough for me not to see it within 15 mins). I see a screenshot from the Clang site that shows steps of working viewed in a web browser: That's probably obtained

Clang Error on “Potential null dereference.”

回眸只為那壹抹淺笑 提交于 2019-12-02 17:51:33
I keep getting Clang errors on the following type of code and I can't figure out why they're erroneous or how to resolve them to Clang's satisfaction: + (NSString *)checkForLength: (NSString *)theString error: (NSError **)error { BOOL hasLength = ([theString length] > 0); if (hasLength) return theString; else { *error = [NSError errorWithDomain:@"ErrorDomain" code:hasLength userInfo:nil]; return nil; } } Leaving aside the utterly-contrived nature of the example (which Clang did object to so it's illustrative enough), Clang balks at the error assignment line with the following objection:

clang-tidy: How to suppress warnings?

跟風遠走 提交于 2019-11-30 11:47:24
I recently started experimenting with the clang-tidy tool of llvm. Now I am trying to suppress false warnings from third party library code. For this I want to use the command line options -header-filter=<string> or -line-filter=<string> but so far without success. So for people with limited time I will put the question here at the beginning and explain later what I already tried. Question What option do I need to give to the clang-tidy tool to suppress a warning from a certain line and file? if this is not possible What option works to suppress warnings from external header files? What I did

How can I make Clang's “scan-build” work with SCons?

独自空忆成欢 提交于 2019-11-30 08:13:13
I've got a project built with SCons and I'm trying to use the Clang Static Analyzer to analyze the code. However, when running scan-build scons SCons seems to ignore the settings introduced by scan-build . How can I make this work? The way scan-build works is it sets up various environment variables that are usually used by build systems (such as make ) to control how the build happens. Some of these are: CC - name of program to use as C compiler CXX - name of program to use as C++ compiler CCC_* - various environment variables that control the behaviour of Clang's static analyzer SCons

clang-tidy: How to suppress warnings?

烈酒焚心 提交于 2019-11-29 17:40:55
问题 I recently started experimenting with the clang-tidy tool of llvm. Now I am trying to suppress false warnings from third party library code. For this I want to use the command line options -header-filter=<string> or -line-filter=<string> but so far without success. So for people with limited time I will put the question here at the beginning and explain later what I already tried. Question What option do I need to give to the clang-tidy tool to suppress a warning from a certain line and file?

How can I make Clang's “scan-build” work with SCons?

旧城冷巷雨未停 提交于 2019-11-29 11:11:03
问题 I've got a project built with SCons and I'm trying to use the Clang Static Analyzer to analyze the code. However, when running scan-build scons SCons seems to ignore the settings introduced by scan-build . How can I make this work? 回答1: The way scan-build works is it sets up various environment variables that are usually used by build systems (such as make ) to control how the build happens. Some of these are: CC - name of program to use as C compiler CXX - name of program to use as C++

Example code to trigger Clang's static analyser

主宰稳场 提交于 2019-11-29 08:04:08
问题 I would like to see a small but complete snippet of code that will cause Clang's static analyser to complain. My motivation is mostly that I'm trying to get it to work on my PIC32 code, and I need a way to distinguish between "all the code is fine" and "it's not actually doing anything". It's also partly curiosity, since I can't seem to come up with a simple example myself. C89/ANSI or C99 is fine, and ideally I'd like to see it pick up a simple memory leak. My usage is clang --analyze test.c

CMake add target for invoking clang analyzer

你说的曾经没有我的故事 提交于 2019-11-29 00:20:43
问题 I'd basically like to achieve the same as http://blog.alexrp.com/2013/09/26/clangs-static-analyzer-and-automake, but with CMake. analyze_srcs = foo.c analyze_plists = $(analyze_srcs:%.c=%.plist) CLEANFILES = $(analyze_plists) $(analyze_plists): %.plist: %.c @echo " CCSA " $@ @$(COMPILE) --analyze $< -o $@ analyze: $(analyze_plists) .PHONY: analyze So you can run make analyze make clean I guess I need to use add_custom_command/add_custom_target and somehow change the "object file" extension