Cppcheck简单测评

Stella981
• 阅读 517

测评代码如下:

#include <cstdio>
#include <string>
int main(void)
{
 // 多了或者少了格式化参数
 ::printf("%d%d%d\n", int(1), int(2));
 ::printf("%d%d%d\n", int(1), int(2), int(3), int(4));
 // 格式化类型不正确
 ::printf("%s\n", std::string("test"));
 ::printf("%d\n", std::string("test"));
 ::printf("%d\n", float(12.34));
 ::printf("%f\n", int(1));
 // 越界
 int a[10] = {0};
 a[10] = 10;
 int b[10] = {0};
 for (int i; i < 11; ++i)
 {
  b[i] = 10;
 }
 for (int i = 0; i < 11; ++i)
 {
  b[i] = 10;
 }
 // 字符串比较的典型错误
 bool bl;
 bl = ("123" == std::string("123").c_str()); // 此处错误没有找到
 if (bl)
 {
 }
 // Cppcheck的一个bug
 std::string str("123");
 ::printf("%d", ("123"==str ? int(1) : int(2))); // 此处误报
 ::system("pause");
 return 0;
}

结果图

Cppcheck简单测评

有误报,有的错误没找到,但瑕不掩瑜。

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
似梦清欢 似梦清欢
2年前
计算(变量)
include<stdio.hintmain()intprice0;printf("请输入金额(元)");scanf("%d",&price);intchange100price;printf("找您%d元\n",change);return0;上述程序编译执行的结果如下:$cp
CuterCorley CuterCorley
3年前
C语言基础习题50例(六)26-30
习题26利用递归方法求5。实现思路:使用递归。代码如下:cinclude<stdio.hintmain(){intrec(intn);intresultrec(5);printf("5%d\n",result);return0;}intrec(intn){if(n1||n
Stella981 Stella981
2年前
AndroidStudio封装SDK的那些事
<divclass"markdown\_views"<!flowchart箭头图标勿删<svgxmlns"http://www.w3.org/2000/svg"style"display:none;"<pathstrokelinecap"round"d"M5,00,2.55,5z"id"raphael
Stella981 Stella981
2年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Wesley13 Wesley13
2年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Stella981 Stella981
2年前
1058 A+B in Hogwarts
纯水include <stdio.hint a1,a2,a3,b1,b2,b3;int main(){freopen("in.txt","r",stdin);scanf("%d.%d.%d %d.%d.%d",&a1,&a2,&a3,&b1,&b2,&b3);
Wesley13 Wesley13
2年前
17张程序员专用的电脑壁纸
!(https://oscimg.oschina.net/oscnet/220dde2448be4f7090da175592bd00f9.gif)1、三思后再写代码!!!!(https://oscimg.oschina.net/oscnet/2babd54776e4453d9872ae80efb1fa1d.png)
可莉 可莉
2年前
1058 A+B in Hogwarts
纯水include <stdio.hint a1,a2,a3,b1,b2,b3;int main(){freopen("in.txt","r",stdin);scanf("%d.%d.%d %d.%d.%d",&a1,&a2,&a3,&b1,&b2,&b3);
Wesley13 Wesley13
2年前
mysql select将多个字段横向合拼到一个字段
表模式:CREATE TABLE tbl_user (  id int(11) NOT NULL AUTO_INCREMENT,  name varchar(255) DEFAULT NULL,  age int(11) DEFAULT NULL,  PRIMARY KEY (id)