I did some professional coding in C for a while, but I'm still puzzled by some pointer related issues. I would really appreciate community help in understanding the issue below.
After splitting the code and the generated kernel file.
void func1()
{
UTYPE *ptr;
...
ptr = &data; --- (1)
...
func2(ptr); --- (2)
...
}
void func2(UTYPE *inp)
{
if(!inp) --- (3)
return;
...
inp = another_ptr; ---- (4)
---- (5)
}
Simplified backtrace from GDB:
Frame 0:
func2(inp = 0x0)
// crash at line (5) due to dereference
Frame 1:
func1: func2(0x0)
// `ptr` at line (2) is 0x0. Why is this so?
Why ptris it displayed as 0x0 (NULL)in frame 1?
When called func2(), its call stack looks like this:
| //local vars |
| |
| another_ptr = |
| NULL |
+---------------+
| return addr |
+---------------+
| input args |
| copy of ptr |
| contents |
| 0x100 |
For func1()its call stack should look like this:
| |
| ptr = 0x100 |
| |
+---------------+
| return addr |
+---------------+
| input args |
| none in this |
| func |
When inpbecomes NULLin func2()in line (4), how is this reflected in func1 ()?