cppcheck

Cppcheck inline suppression not working

*爱你&永不变心* 提交于 2021-01-27 14:24:00
问题 Example code: class Foo { // cppcheck-suppress noExplicitConstructor Foo(int foo) { } } Cppcheck call: $ cppcheck.exe --enable=all foo.cpp Checking foo.cpp... [foo.cpp:3]: (style) Class 'Foo' has a constructor with 1 argument that is not explicit. How can I suppress this error? 回答1: This way: class Foo { // cppcheck-suppress noExplicitConstructor Foo(int foo) { } }; It requires --inline-suppr as command line argument. 来源: https://stackoverflow.com/questions/37701104/cppcheck-inline

cppcheck can't find include files

核能气质少年 提交于 2020-12-29 02:43:35
问题 cppcheck can't find even standard headers such as iostream. Any ideas? I am using Ubuntu 11.04 and cppcheck from the repository. 回答1: cppcheck is really bad at finding standard include headers, on Mac and Linux. Fortunately, you can suppress this check, and only scan your custom header files: cppcheck --enable=all --suppress=missingIncludeSystem . 回答2: It isn’t recommended to provide the paths to the standard C/C++ headers - Cppcheck has internal knowledge about ANSI C/C++ and it isn’t

cppcheck can't find include files

做~自己de王妃 提交于 2020-12-29 02:42:24
问题 cppcheck can't find even standard headers such as iostream. Any ideas? I am using Ubuntu 11.04 and cppcheck from the repository. 回答1: cppcheck is really bad at finding standard include headers, on Mac and Linux. Fortunately, you can suppress this check, and only scan your custom header files: cppcheck --enable=all --suppress=missingIncludeSystem . 回答2: It isn’t recommended to provide the paths to the standard C/C++ headers - Cppcheck has internal knowledge about ANSI C/C++ and it isn’t

linux下vscode备忘

喜欢而已 提交于 2020-11-19 07:26:47
vscode如何自定义,如何方便地编写c/c++ vscode支持vim、sublime快捷键,在设置->keymap可以安装相应插件 vscode默认的快捷键支持自定义,打开keyboard shortcuts可以绑定新的键位, ~/.config/Code/User/keybindings.json对应了新的改键 主题thems也可以自定义 vscode的配置文件为json,有三级配置,defaultsettings.json是read-only,用户级配置 是settings.json,第三级配置是workspace的settings.json。后一级配置的键值对可以 覆盖前一级的。json的格式可以查阅网上文档。 插件也是可以设置的,插件的settings也有UI界面和json源文件可以设置 插件介绍 Atom One Dark Them:提供Atom风格的主题 C/C++ Themes:提供了两款主题 C/C++:提供了代码提示、格式化、查看定义等 Clang-Format:提供了Clang风格的格式化 cppcheck:需要先安装sudo apt-get install cppcheck,c/c++静态检查工具 vscode-icons:文件图标美化 code-runner:运行代码,用户级settings.json里的code-runner

c/c++常用工具使用(linux下)

我怕爱的太早我们不能终老 提交于 2020-10-03 18:50:25
格式化工具: astyle libevent工具: doxygen :(创建文档 从注释里面提取对应的文档) 安装: sudo apt-get install -y doxygen 步骤:1.在*.h文件写注释 并将文档提取出出来 eg: 2. xx -doxygen -g 自动生成Doxyfile文件 3.vim DoxyFile 进行参数的修改 eg: DROJECINAME=" " DROJECTBRIEF=" " OUTPUT_LANGUAGE=" " 等相关参数的修改 4.doxygen 生成 html文件进行访问查看 cppcheck : 1.安装: sudo apt-get install -y cppcheck 2.文档:cppcheck 3.使用: cppcheck --enable=all ./ cppcheck --enable=all --check-config xx.cpp valgrind :用于检查内存泄漏 使用 valgrind ./a.out cpptest :c++用于做单元测试的库 1.安装: sudo apt-get install -y libcpptest-dev 2.编写测试用例: 文件gcov(系统自带) lcov自己安装 来源: oschina 链接: https://my.oschina.net/u/4406698/blog

如何将std :: string转换为int?

这一生的挚爱 提交于 2020-02-26 10:15:30
只是有一个简短的问题。 我在互联网上看了很多,我找到了一些解决方案,但没有一个已经有效。 看一下将字符串转换为int,我不是指ASCII码。 为了快速减少,我们将方程作为字符串传递。 我们要将其分解,正确格式化并求解线性方程。 现在,在说,我无法将字符串转换为int。 我知道字符串将采用格式(-5)或(25)等,所以它肯定是一个int。 但是我们如何从字符串中提取它? 我想的一种方法是通过字符串运行for / while循环,检查一个数字,然后提取所有数字,然后查看是否有一个前导' - ',如果存在,则将int乘以 - 1。 虽然这个小问题看起来有点过于复杂。 有任何想法吗? #1楼 还有另一种简单的方法:假设你有一个像 c='4' 的字符,那么你可以做以下步骤之一: 1st:int q q=(int) c ; (q is now 52 in ascii table ) . q=q-48; remember that adding 48 to digits is their ascii code . 第二种方式: q=c-'0'; the same , character '0' means 48 #2楼 可能的选项如下所述: 1.第一个选项:sscanf() #include <cstdio> #include <string> int i; float f; double d;

Which error format should be used for Vim and Cppcheck?

时光毁灭记忆、已成空白 提交于 2020-01-05 07:28:11
问题 I use the following script to integrate Cppcheck with gVim: " vimcppcheck.vim " =================================================================== " Code Checking with cppcheck (1) " =================================================================== function! Cppcheck_1() set makeprg=cppcheck\ --enable=all\ % setlocal errorformat=[%f:%l]:%m let curr_dir = expand('%:h') if curr_dir == '' let curr_dir = '.' endif echo curr_dir execute 'lcd ' . curr_dir execute 'make' execute 'lcd -' exe "

stumbling upon a non-trivial bool scenario in C++

空扰寡人 提交于 2020-01-05 04:27:10
问题 When Cppcheck runs over this code, [1] it complains about an error : void bool_express(bool aPre, bool aX, bool aPost) { bool x; const bool pre = aPre; if (pre) { x = aX; } const bool post = aPost; // error checking passage of the original code: if ( !pre || !x || !post ) { if ( !pre ) { trace("pre failed"); } else if ( !x ) { // <-- HERE Cppcheck complains trace("x failed"); } else { trace("post failed"); } } else { // success passage of the original code: trace("ok"); } } This is the

Why does Cppcheck not find this obvious array out-of-bounds error?

人盡茶涼 提交于 2020-01-03 09:03:37
问题 I installed the Cppcheck tool for static code analysis of my C++ project and got the feeling that it performs poorly. For example, can anyone tell me why Cppcheck is unable to find an array out-of-bounds error in the following code? void f(int c) { char *p = new char[10]; p[c] = 42; } void g() { f(100); } There's an online demo where this code can be conveniently checked using Cppcheck. All it comes up with is a memory leak at line 4, no signs of a potential buffer overflow. 回答1: Because it

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