cancel
Showing results for 
Search instead for 
Did you mean: 

No return function

lgiordano2
Associate II
Posted on November 01, 2007 at 12:18

No return function

6 REPLIES 6
lgiordano2
Associate II
Posted on October 29, 2007 at 15:21

Hi,

I am using CrossStudio. My application used to crash (in fact, using a JTAG debugger and halting it, it was at either undef handler or fiq handler, although it is not supposed to do so).

I found out I have something like that:

Code:

int function(int a, int b)

{

if (some_test_here) {

return (a+b)

}

}

As you can see, there is not a return value.. Can it be a cause of crashing?

I know it is a big mistake to ''miss'' a return. As long as I know, the returned value is pushed into the stack, then the caller pops that value and uses it (or not). Is it possible that missing a return, stack gets corrupted?

Regards,

kleshov
Associate II
Posted on October 30, 2007 at 02:43

As far as I know, the return value is stored in a CPU register. So missing a return statement would mean that the caller will get garbage instead of the return value. You can see it for yourself, just look at the disassembly of the function.

lgiordano2
Associate II
Posted on October 30, 2007 at 07:57

Thank you for your reply.

According to that, it is not a reason for application hanging? Assuming that returned value is handled, even if garbage is returned.

Regards,

kleshov
Associate II
Posted on October 31, 2007 at 04:35

Exactly. I would not expect this to be a reason for the app hanging. More likely reasons are stack overflow, writing past array boundaries, bad function pointers and so on.

lgiordano2
Associate II
Posted on November 01, 2007 at 12:03

Well, it is strange because since I added the missing return, my application has not hanged again. It used to hang easily and frequently, but now it doesn't. Moreover, debugging with some leds, the 'hanging scope' was about that function.

I will go on looking for another hanging reason...

Regards,

kleshov
Associate II
Posted on November 01, 2007 at 12:18

I could be wrong about this. Normally, if the return value is a struct, it is returned using the stack. I don't know about gcc, maybe for some strange reason it returns ints using the stack, but that seems unlikely.

Anyway, you can know for sure if you analyze the disassembly of the relevant code before and after adding the missing return.