Insure++ Reference - RETURN_DANGLING
This error is generated whenever a function returns a pointer to a
(non-static) local variable. Since the stack frame of this routine will
disappear when the function returns, this pointer is never valid.
The following code shows the routine foo returning
a pointer to a local variable.
1: /*
2: * File: retdngl.c
3: */
4: char *foo()
5: {
6: char b[10];
7: return b;
8: }
9:
10: main()
11: {
12: char *a = foo();
13: return (0);
14: }
1. [retdngl.c:7] **RETURN_DANGLING**
2. Returning pointer to local variable: b.
>> return b;
- Source line at which the problem was detected.
- Description of the problem and the expression that is in error.
The pointer returned in this manner can be made legal in one of
several ways.
Occasionally, the value returned from the function is never used in
which case it is safest to change the declaration of the routine to
indicate that no value is returned.
READ_WILD
RETURN FAILURE
|