No return function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2007-11-01 4:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2007-10-29 7:21 AM
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,- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2007-10-29 6:43 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2007-10-29 11:57 PM
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,- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2007-10-30 8:35 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2007-11-01 4:03 AM
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,- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2007-11-01 4:18 AM
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.