2019-03-18 06:58:12 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main() {
|
2021-08-07 20:51:18 +02:00
|
|
|
printf("Hello world!\n");
|
2019-03-18 06:58:12 +01:00
|
|
|
|
2021-08-07 20:51:18 +02:00
|
|
|
int* pI = (int*)malloc(sizeof(int));
|
|
|
|
int j;
|
|
|
|
printf("Now reading uninitialized memory\n");
|
|
|
|
j = *pI+2;
|
|
|
|
printf("Did you notice? (value was %i)\n",j);
|
|
|
|
free(pI);
|
|
|
|
printf("(No memory leak here)\n");
|
2019-03-18 06:58:12 +01:00
|
|
|
|
2021-08-07 20:51:18 +02:00
|
|
|
int* pJ;
|
|
|
|
printf("Now writing to uninitialized pointer\n");
|
|
|
|
*pJ = j;
|
|
|
|
printf("Did you notice?\n");
|
2019-03-18 06:58:12 +01:00
|
|
|
|
2021-08-07 20:51:18 +02:00
|
|
|
// valgrind reports 8, but that's ok
|
|
|
|
printf("There should be 2 errors in this run\n");
|
|
|
|
return 0;
|
2019-03-18 06:58:12 +01:00
|
|
|
}
|