I have the following code:
Expand|Select|Wrap|Line Numbers
- func1()
- {
- unsigned int i;
- int j = 3;
- switch(j)
- {
- case 3:
- i = -1UL;
- break;
- default:
- /*some operation*/
- }
- return(i);
- }
However, we have a tool which will compile c programs to see if there is any error in the code, maybe to identify mem leaks, dangling pointers etc.
When i use this tool to compile the above code, it says that we are READ_DANGLING at the return statement in the above code.
When I move the return statement inside case 1: after "i = -1UL", it doesn't show this error.
Assume that moving return inside or outside the switch does same operation.
Now my question:
1) why is it saying that we are doing a READ_DANGLING?
2) is there any scope w.r.t to variable returning within and outside switch
3) When i assign any other value to i other that -1UL, this issue is not seen. So is there any error with the way i am assigning the value to variable "i"??
Please help me in understanding the above.
--Thanks