cppcheck | static analysis of C/C++ code | Code Analyzer library
kandi X-RAY | cppcheck Summary
kandi X-RAY | cppcheck Summary
The original name of this program was "C++check", but it was later changed to "Cppcheck". Despite the name, Cppcheck is designed for both C and C++.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of cppcheck
cppcheck Key Features
cppcheck Examples and Code Snippets
Community Discussions
Trending Discussions on cppcheck
QUESTION
I am developing C
code on Ubuntu 20.04
.
By running cppcheck -q --project=build/proj1/compile_commands.json --file-filter='src/base/Myfile.c'
I got the error
...ANSWER
Answered 2022-Feb-11 at 13:35It looks like the version of cppcheck
included in Ubuntu 20.04 is not the latest:
QUESTION
I used to work with cppcheck for a long time and for use within eclipse I made use of the plugin cppcheclipse. Now I am setting up a new development PC and thus am trying to find the way to install it. Obviously the old update site dl.bintray.com disappeared and I did not yet find a new way to get it. The same error comes up when I work with the marketplace. Does anyone by chance know where to get it nowadays?
Thanks in advance! Regards, Christoph
...ANSWER
Answered 2022-Feb-11 at 12:57You can find an answer here: https://github.com/kwin/cppcheclipse/issues/108
and the following download link here.
So work-around to install the plugin:
QUESTION
CppCheck is flagging the definition of BufLen as an unusedStructMember, even though it is used on the next line to define the length of the array.
...(style) struct member 'TxDetails_t::BufLen' is never used. [unusedStructMember]
ANSWER
Answered 2022-Jan-11 at 10:27This is indeed a false positive and it is fixed in the upcoming Cppcheck 2.7. I can reproduce it with 2.6 but not with the latest head.
Looking at the list of fixed issues it appears you encountered https://trac.cppcheck.net/ticket/10485.
QUESTION
My project has pretty complex structure. It looks something like this:
...ANSWER
Answered 2021-Oct-30 at 11:31The problem was that .h files where still checked, despite -i flag. Solution:
QUESTION
My objective is to install CppCheck in a Microsoft-Hosted image in Azure Pipelines. I already did this for an Ubuntu image, but CppCheck for Ubuntu is outdated. My pipeline:
...ANSWER
Answered 2021-Oct-27 at 08:48How to install an .msi program in Azure Pipeline (Windows)
You could use the Powershell task to install the .msi file:
QUESTION
In the C++ code below, a segmentation fault occurs before the first line of main()
is executed.
This happens even though there are no objects to be constructed before entering main()
and it does not happen if I remove a (large) variable definition at the second line of main()
.
I assume the segmentation fault occurs because of the size of the variable being defined. My question is why does this occur before the prior line is executed?
It would seem this shouldn't be occurring due to instruction reordering by the optimizer. I say this based on the compilation options selected and based on debug output.
Is the size of the (array) variable being defined blowing the stack / causing the segfault?
It would seem so since using a smaller array (e.g. 15 elements) does not result in a segmentation fault and since the expected output to stdout is seen.
ANSWER
Answered 2021-Oct-03 at 22:03This is definitely a stack overflow. sizeof(dynamic_loop_functor_t)
is nearly 64 MiB, and the default stack size limit on most Linux distributions is only 8 MiB. So the crash is not surprising.
The remaining question is, why does the debugger identify the crash as coming from inside std::operator<<
? The actual segfault results from the CPU exception raised by the first instruction to access to an address beyond the stack limit. The debugger only gets the address of the faulting instruction, and has to use the debug information provided by the compiler to associate this with a particular line of source code.
The results of this process are not always intuitive. There is not always a clear correspondence between instructions and source lines, especially when the optimizer may reorder instructions or combine code coming from different lines. Also, there are many cases where a bug or problem with one source line can cause a fault in another section of code that is otherwise innocent. So the source line shown by the debugger should always be taken with a grain of salt.
In this case, what happened is as follows.
The compiler determines the total amount of stack space to be needed by all local variables, and allocates it by subtracting this number from the stack pointer at the very beginning of the function, in the prologue. This is more efficient than doing a separate allocation for each local variable at the point of its declaration. (Note that constructors, if any, are not called until the point in the code where the variable's declaration actually appears.)
The prologue code is typically not associated with any particular line of source code, or maybe with the line containing the function's opening
{
. But in any case, subtracting from the stack pointer is a pure register operation; it does not access memory and therefore cannot cause a segfault by itself. Nonetheless, the stack pointer is now pointing outside the area mapped for the stack, so the next attempt to access memory near the stack pointer will segfault.The next few instructions of
main
execute thecout << "Starting main"
. This is conceptually a call to the overloadedoperator<<
from the standard library; but in GCC's libstdc++, theoperator<<
is a very short function that simply calls an internal helper function named__ostream_insert
. Since it is so short, the compiler decides to inlineoperator<<
intomain
, and somain
actually contains a call to__ostream_insert
. This is the instruction that faults: the x86call
instruction pushes a return address to the stack, and the stack pointer, as noted, is out of bounds.Now the instructions that set up arguments and call
__ostream_insert
are marked by the debug info as corresponding to the source ofoperator<<
, in theheader file - even though those instructions have been inlined into
main
. Hence your debugger shows the crash as having occurred "inside"operator<<
.Had the compiler not inlined
operator<<
(e.g. if you compile without optimization), thenmain
would have contained an actual call tooperator<<
, and this call is what would have crashed. In that case the traceback would have pointed to thecout << "Starting main"
line inmain
itself - misleading in a different way.
Note that you can have GCC warn you about functions that use a large amount of stack with the options -Wstack-usage=NNN
or -Wframe-larger-than=NNN
. These are not enabled by -Wall
, but could be useful to add to your build, especially if you expect to use large local objects. Specifying either of them, with a reasonable number for NNN
(say 4000000), I get a warning on your main
function.
QUESTION
I'm trying to upload my copy of Godot to my own github and it complains:
...ANSWER
Answered 2021-Sep-12 at 21:58The pattern /Godot.app
should match your file just fine. However, if the file is already added to the repository, then .gitignore
has no effect on it. The .gitignore
file affects only files which are untracked.
In your case, your file is in the history, and it needs to be removed from the entire history if you want to upload it to GitHub. You can do a git rebase -i
to go back in history to the point at which it was added and remove it from history, or, if it was added in the most recent commit, you can remove it with git rm -r Godot.app
and then run git commit --amend
.
You could also use git filter-branch
or git filter-repo
to filter it out from the history.
QUESTION
On the following code
...ANSWER
Answered 2021-Aug-25 at 13:39When you do
QUESTION
So My Workspace Screenshot After Trying a while i cant Get Cmake To find the required packages even after i did everything as shown in vcpkg
...ANSWER
Answered 2021-Aug-11 at 13:42You can't set CMAKE_TOOLCHAIN_FILE
after the call to project()
. That's the command responsible for loading the toolchain file in the first place. Move it before the call to project()
or better yet: set it at the command line or in a preset.
Also, unless you're actually using CMake 3.0.0, you shouldn't set it as a minimum. CMake is not forwards compatible, so without actually testing it on the minimum version, you have no way of knowing whether it will work that far back.
QUESTION
In the list of cppcheck rules there is
I've written a call to a virtual functions in several classes in my solution and run cppcheck o them, but it didn't show this error.
I've used GUI and also run cppcheck from command line with --enable=style and --enable=all
How can I make cppcheck to show this issue? I'm using latest cppcheck
Another dummy code I've run cppcheck on
...ANSWER
Answered 2021-Jul-07 at 14:02I found this comment https://sourceforge.net/p/cppcheck/discussion/general/thread/b18f7aaf/#d726
It will be fixed in the next release. For now I have disabled the check. But it can be enabled again if we write such warnings properly. The checker must ensure that the class is a base class!
The post relates to 1.84
Looking at the code it is still disabled: https://github.com/danmar/cppcheck/blob/6397e29f84de53655904326ef1ca892a509275c5/lib/checkclass.h
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cppcheck
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page