Local Program Analysis

The source checker uses local analysis of each program unit to check for various kinds of errors, warnings, and/or debatable points in a program. Examples of these errors are:

The following examples illustrate local program analysis.

Example 1: Object is smaller than required size

1 #include <stdio.h>

2 #include <string.h>

3

4 int main(void){

5 char string[10];

6

7 strcpy(string, "Hello world from");

8 printf("%s\n",string);

9

10 return 0;

11 }

The following message is issued :

f1.c(7): error #12224: Buffer overflow: size of object "string" (10 bytes) is less than required size (17 bytes)

Example 2: Memory Leak

File f1.c contains the following:

1 #include <stdio.h>

2 #include <malloc.h>

3

4 int main(void) {

5 float **ptr;

6

7 ptr = (float **)malloc(8);

8 if (ptr == NULL) exit(1);

9 *ptr = (float*)malloc(sizeof(float));

10 if (*ptr == NULL) exit(1);

11 **ptr = 3.14;

12 printf("%f\n",**ptr);

13 free(ptr);

14 return 0;

15 }

The source checker issues the following message:

f1.c(14): error #12121: memory leak: dynamic memory allocated at (file:f1.c line:9) is not freed at this point