-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
42 lines (35 loc) · 715 Bytes
/
main.cpp
File metadata and controls
42 lines (35 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <iostream>
int fun(int a, int b);
int main(void)
{
int a;
char buffer[10];
char index = 1;
int x = fun(40, 2);
int y = fun(40, 2);
/* Vulnerability: Array index out of bound */
buffer[10] = 1;
/* Vulnerability: Array index used before limits check*/
buffer[a] = 'a';
/* Code smell: 'char' type used as array index */
buffer[index] = '1';
/* Bug: Access to an uninitialized value*/
if (1 == a)
{
printf("a = 1");
}
a = 0;
if (x != 42)
{
/* NOK, empty code blocks generate violations */
}
/* Bug: Division by zero */
x /= a;
printf("40 + 2 = %d\n", x);
printf("fun = %d\n", y);
}
int fun(int a, int b)
{
return a * b;
}