Closed WILDWEEGEE closed 6 years ago
<!DOCTYPE html>
File: | test.c |
Location: | line 33, column 32 |
Description: | Dereference of null pointer (loaded from variable 'p2') |
1 | #include <stdio.h> | |||
2 | #include <string.h> | |||
3 | #include "helper.h" | |||
4 | ||||
5 | int otherHelper(int* p) { | |||
6 | return *p - 5; | |||
7 | } | |||
8 | ||||
9 | // Dereference pointer without checking if NULL | |||
10 | int helper2(int* p) { | |||
11 | printf("wow\n"); | |||
12 | return *p + 4; | |||
13 | } | |||
14 | ||||
15 | int main(int argc, char* argv[]) { | |||
16 | int num1 = 15; | |||
17 | int num2 = 20; | |||
18 | ||||
19 | int* p1 = &num1; | |||
20 | int* p2 = &num2; | |||
21 | ||||
22 | if (argc >= 2 && strcmp(argv[1], "wow") == 0) { | |||
| ||||
23 | p1 = NULL((void*)0); | |||
24 | } | |||
25 | ||||
26 | if (argc >= 2 && strcmp(argv[1], "test") == 0) { | |||
27 | p2 = NULL((void*)0); | |||
28 | } | |||
29 | ||||
30 | printf("amazing\n"); | |||
31 | ||||
32 | printf("num1 + 4 is %d\n", helper2(p1)); | |||
33 | printf("num2 - 5 is %d\n", *p2); | |||
| ||||
34 | ||||
35 | int* p3 = NULL((void*)0); | |||
36 | ||||
37 | return *p3; | |||
38 | } |
<!DOCTYPE html>
Bug Summary
Annotated Source Code