All Questions
Tagged with static-code-analysis or static-analysis
2,722 questions
0 votes
1 answer
139 views
How to detect redundant assignments with Python linters?
Consider this small function: def test(): x = 1 x = 2 x = 3 return x + 1 Apparently, the first two assignments to x have no effect here and can be removed. Yet surprisingly, pylint/...
-2 votes
1 answer
76 views
SemGrep java rule for shadowing field name with the variable
We have SemGrep which we are allowed using as a static code analysis tool. I'm trying to write a Java rule which verifies if the variable name has exactly the same name as the field name within the ...
2 votes
4 answers
412 views
How to suppress this false positive warning from Clang static code analyzer?
#include <stdio.h> #include <stdlib.h> typedef struct { int a; } tempStruct1; typedef struct { int b; } tempStruct2; typedef struct { tempStruct1 *temp1; tempStruct2 *...
0 votes
0 answers
81 views
autoconf/CMake-like file generation for TypeScript
In C/C++, it is possible to write something like: // version.h extern const char *branch; extern const char *hash; extern const char *status; extern const char *timestamp; // version.c (...
0 votes
0 answers
46 views
Liveness Analysis doesn't produce expected result
First a bit of context. Consider the code: void foo(double* b){ int a = 100; a = 101; b[1] += b[a]; } I have a visitor, that has VisitArraySubscriptExpr(ASE), where I perform ...
0 votes
0 answers
154 views
Detect unimplemented class methods without a program failing to link
Suppose I am working on a library with a decent number of classes, most of them having a bunch of methods, in addition to the basic ctors and dtor. For reasons, the method implementations are spread ...
0 votes
1 answer
87 views
Does the react context API not hide dependencies?
When I make a component that relies on something like the currently chosen language for example, or maybe a special query function to fetch data, and I provide either of these things via a ...
1 vote
1 answer
92 views
Creating analyzer in golang.org/x/tools that runs for all the packages, not one time per package
I want to create an analysis.Analyzer and define a run function on it that runs once per all the codebase, and not once per package. If I check the documentation of the Run field, I see: // Run ...
0 votes
1 answer
322 views
Is clang-tidy '-checks=clang-analyzer-*' a drop in replacement for scan-build and clang-check -analyze?
Is clang-tidy '-checks=clang-analyzer-*' a drop in replacement for scan-build and clang-check -analyze? If I'm using the former, is there any need for using latters again? Previously there are two ...
1 vote
1 answer
82 views
Checkstyle: ImportOrder vs CustomImportOrder
In the Checkstyle tool what's the difference between the ImportOrder and the CustomImportOrder rules? At the first glance they look similar.
10 votes
3 answers
865 views
Annotating intentional infinite loop to satisfy "-fanalyzer"
I have a following embedded system optimization case (simplified). int main() { while (1) { // Do something if (unrecoverable_error) { __breakpoint(); while(1); } } } ...
1 vote
0 answers
192 views
Clazy fails to process files including nlohmann/json.hpp
Context: I'm using Clazy to analyze my C++ project, which includes the nlohmann/json.hpp header. Problem: Clazy fails to process files that include this header. What I've tried: Wrapping the include ...
1 vote
1 answer
191 views
Why isn't PHPStan complaining about invalid array keys?
Here's the code: <?php declare(strict_types=1); /** * @param array{key?: string} $options */ function hello($options) { var_dump($options); } hello([ 'WRONG_KEY' => '...', ]); I ...
1 vote
0 answers
45 views
Deadlock: multithreading with CPAchecker
I tried to find a way to verify deadlock with CPA checker. My goal is to check the "problem of philosofer". I found a lot of problem with CPA checker and threading. Someone can help me find ...
0 votes
1 answer
28 views
ClangFormat style to handle non-idiomatic whitespace?
Are there any ClangFormat styles (or other tools) which will handle excessive newlines? With two or more newlines after the function parameter parentheses, as in the example below, none of the styles ...