...
In this example, the function funcinit_array() incorrectly returns a pointer to a local stack variable.
| Code Block | ||
|---|---|---|
| ||
char *funcinit_array() { char aarray[10] ; /* OperateInitialize onarray a */ return &a[0]array; } |
Compiling with appropriate warning levels should generate a warning when a local stack variable is returned from a function.
...
Correcting this example depends on the intent of the programmer. If the intent is to modify the value of a array and have that modification persist outside of the scope of funcinit_array(), then the desired behavior can be achieved by declaring a array elsewhere and passing it as a parameter to funcinit_array().
| Code Block | ||
|---|---|---|
| ||
void funcinit_array(char aarray[]) { /* Operate on aarray */ return; } |
Risk Assessment
...