2018-01-23 17:18:47 +01:00
|
|
|
// To test:
|
|
|
|
// ~/cppcheck/cppcheck --dump cert-test.c && python ../cert.py -verify cert-test.c.dump
|
|
|
|
struct S {
|
|
|
|
short a;
|
|
|
|
short b;
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack()
|
|
|
|
struct PackedStruct {
|
|
|
|
short a;
|
|
|
|
short b;
|
|
|
|
};
|
|
|
|
|
2018-04-03 13:35:19 +02:00
|
|
|
void dostuff(int *data);
|
|
|
|
|
|
|
|
void exp05()
|
|
|
|
{
|
|
|
|
const int x = 42;
|
2018-04-03 15:12:01 +02:00
|
|
|
int y = (int)x;
|
|
|
|
|
2018-04-03 13:35:19 +02:00
|
|
|
int *p;
|
|
|
|
p = (int *)&x; // cert-EXP05-C
|
|
|
|
|
|
|
|
const int data[] = {1,2,3,4};
|
|
|
|
dostuff(data); // cert-EXP05-C
|
|
|
|
}
|
|
|
|
|
2018-04-12 20:23:50 +02:00
|
|
|
void print(const char *p);
|
|
|
|
void exp05_fp() {
|
|
|
|
print("hello");
|
|
|
|
}
|
|
|
|
|
2018-01-23 17:18:47 +01:00
|
|
|
void exp42()
|
|
|
|
{
|
|
|
|
struct S s1 = {1,2};
|
|
|
|
struct S s2 = {1,2};
|
|
|
|
memcmp(&s1, &s2, sizeof(struct S)); // cert-EXP42-C
|
|
|
|
|
|
|
|
struct PackedStruct s3 = {1,2};
|
|
|
|
struct PackedStruct s4 = {1,2};
|
|
|
|
memcmp(&s3, &s4, sizeof(struct S));
|
|
|
|
}
|
|
|
|
|
2018-01-23 22:43:29 +01:00
|
|
|
void exp46()
|
|
|
|
{
|
|
|
|
if ((x == y) & z) {} // cert-EXP46-c
|
|
|
|
}
|
|
|
|
|
2018-01-23 17:18:47 +01:00
|
|
|
unsigned char int31(int x)
|
|
|
|
{
|
|
|
|
x = (unsigned char)1000; // cert-INT31-c
|
|
|
|
x = (signed char)0xff; // cert-INT31-c
|
|
|
|
x = (unsigned char)-1; // cert-INT31-c
|
|
|
|
x = (unsigned long long)-1; // cert-INT31-c
|
|
|
|
}
|
2018-08-24 15:05:50 +02:00
|
|
|
|
|
|
|
void msc30()
|
|
|
|
{
|
|
|
|
unsigned int num = rand(); // cert-MSC30-c
|
|
|
|
int rand = 5;
|
|
|
|
int a = rand;
|
|
|
|
}
|
2019-06-17 20:42:23 +02:00
|
|
|
|
2019-06-26 18:49:47 +02:00
|
|
|
void exp15()
|
|
|
|
{
|
|
|
|
int x=5, y=7;
|
|
|
|
|
|
|
|
if(x==y); //cert-EXP15-C
|
|
|
|
{
|
|
|
|
printf("not working\n");
|
|
|
|
}
|
|
|
|
if(x)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2019-06-24 18:41:43 +02:00
|
|
|
void str03()
|
|
|
|
{
|
|
|
|
char *string_data=(char*)malloc(16);
|
|
|
|
char a[16];
|
|
|
|
int d;
|
|
|
|
strncpy(a, string_data, sizeof(a)); //cert-STR03-C
|
|
|
|
strncpy(a, string_data, 5); d=sizeof(int);
|
|
|
|
}
|
|
|
|
|
2019-06-17 20:42:23 +02:00
|
|
|
void str05()
|
|
|
|
{
|
2019-06-26 18:49:47 +02:00
|
|
|
int x=5, y=7;
|
|
|
|
|
|
|
|
if(x==y); //cert-EXP15-C
|
|
|
|
{
|
|
|
|
printf("not working\n");
|
|
|
|
}
|
|
|
|
if(x)
|
|
|
|
;
|
2019-06-17 20:42:23 +02:00
|
|
|
}
|
|
|
|
|
2019-06-23 13:59:24 +02:00
|
|
|
void str07(char *buf, const char *newBuf)
|
|
|
|
{
|
|
|
|
const char *str="test";
|
|
|
|
strcat(buf,"bla");
|
|
|
|
strcat(buf, str); //cert-STR07-C
|
|
|
|
strcat(buf, newBuf); //cert-STR07-C
|
|
|
|
strcpy(str, newBuf); //cert-STR07-C
|
|
|
|
}
|