-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling a value returning function that doesn't actually return anything crashes the program #236
Comments
Good catch. That is a programming error and according to the C spec is "undefined behavior" so crashing is acceptable there. I was going to port in the following patch from the ESP8266, but completely forgot. Thanks for reminding me! |
Yeah it definitely isn't a mistake I usually do but this completely escaped me for a few hours until I finally realised what was going on😅 |
Fixes #236 Compiler warning flags were completely ignored/missed in platform.txt. Add them, as normal, and include -Werror=return-type because GCC will produce crashing apps when a function return value is missing.
Not only did I need to add the patch, it turns out I had forgot to add any of the warning options to the actual compile options. D'oh! No matter what the warning options, your sample will fail to build with the following report using the PR:
|
Fixes #236 Compiler warning flags were completely ignored/missed in platform.txt. Add them, as normal, and include -Werror=return-type because GCC will produce crashing apps when a function return value is missing.
I just spent a few hours trying to figure out what was wrong with my code as it was behaving very strangely (a for loop wouldn't increment) altough it was working just fine with the oficial core as well as with other microcontrollers.
I found I had defined a value returning function with several ifs and returns but the part the code was following didn't actually have a return in the end and therefore the pico was crashing. Here is a very simple example that replicates the issue in case my explanation isn't clear enough. Notice how printTest( ) doesn't return anything but is defined as an int returning function. I can see how a lot of people could get stuck with this issue as it isn't really easy to debug if the code is large.
The text was updated successfully, but these errors were encountered: