-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add error check in Stream constructor #4259
Conversation
platform/Stream.cpp
Outdated
if (_file) | ||
mbed_set_unbuffered_stream(_file); | ||
else | ||
error("Stream obj failure, errno=%d\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be taking in errno?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops indeed !
platform/Stream.cpp
Outdated
@@ -23,7 +25,10 @@ Stream::Stream(const char *name) : FileLike(name), _file(NULL) { | |||
char buf[12]; /* :0x12345678 + null byte */ | |||
std::sprintf(buf, ":%p", this); | |||
_file = std::fopen(buf, "w+"); | |||
mbed_set_unbuffered_stream(_file); | |||
if (_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit if you're already changing the file: We use squiggly brackets on single line if statement:
if (_file) {
blah
} else {
bleh
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will take also into account - thx !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey it looks good! (other than small nits)
failing on file allocation / opening during Stream creation. The consequence was application continues running, but any printf to the Serial object whose Stream was not properly created would not show any error (and characters would not show either) Let's add a check to properly inform user of the error.
dbf3b20
to
4ad4b2a
Compare
@geky thx for the comments - I pushed an updated version of the patch |
Thanks! This looks great! 😄 |
Result: FAILUREYour command has finished executing! Here's what you wrote!
OutputTest failed! |
Restarting /morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
This is reliant on #3867 which is targeted for 5.5.0 thus re-targeting this one also for 5.5.0 |
Proposal following discussion on #687
Description
On small targets there might be memory issues that lead to failing on file allocaiton / opening during Stream creation.
The consequence was application continues running, but any printf
to the Serial object whose Stream was not properly created
would not show any error (and characters would not show either)
Let's add a check to be properly inform user of the error.
Status
READY