...
Code Block | ||
---|---|---|
| ||
#include <stdlib.h>
/* // ... */
char *p = malloc(10);
|
...
Code Block | ||
---|---|---|
| ||
func(1, 2);
/* // ... */
int func(int one, int two, int three){
printf("%d %d %d", one, two, three);
return 1;
}
|
...
Code Block | ||
---|---|---|
| ||
int func(int, int, int); /* // ... */ func(1, 2, 3); /* // ... */ int func(int one, int two, int three){ printf("%d %d %d", one, two, three); return 1; } |
...
Code Block | ||
---|---|---|
| ||
int add(int x, int y, int z) {
return x + y + z;
}
int main(int argc, char *argv[]) {
int (*fn_ptr) (int, int);
int res;
fn_ptr = add;
res = fn_ptr(2, 3); /* incorrect */
/* // ... */
return 0;
}
|
Compliant Solution: (function pointers)
...
Code Block | ||
---|---|---|
| ||
int add(int x, int y, int z) {
return x + y + z;
}
int main(int argc, char *argv[]) {
int (*fn_ptr) (int, int, int) ;
int res;
fn_ptr = add;
res = fn_ptr(2, 3, 4);
/* // ... */
return 0;
}
|
Risk Assessment
...