Skip to content
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

Merged
merged 1 commit into from
May 4, 2017

Conversation

LMESTM
Copy link
Contributor

@LMESTM LMESTM commented May 2, 2017

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

@LMESTM LMESTM changed the title Add error check in Steam constructor Add error check in Stream constructor May 2, 2017
if (_file)
mbed_set_unbuffered_stream(_file);
else
error("Stream obj failure, errno=%d\r\n");
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops indeed !

@@ -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)
Copy link
Contributor

@geky geky May 2, 2017

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
}

Copy link
Contributor Author

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 !

Copy link
Contributor

@geky geky left a 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.
@LMESTM
Copy link
Contributor Author

LMESTM commented May 2, 2017

@geky thx for the comments - I pushed an updated version of the patch

@geky
Copy link
Contributor

geky commented May 2, 2017

Thanks! This looks great! 😄
/morph test

@mbed-bot
Copy link

mbed-bot commented May 3, 2017

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 132

Test failed!

@0xc0170
Copy link
Contributor

0xc0170 commented May 3, 2017

Restarting

/morph test

@mbed-bot
Copy link

mbed-bot commented May 3, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 137

All builds and test passed!

@adbridge adbridge merged commit 8543279 into ARMmbed:master May 4, 2017
@adbridge
Copy link
Contributor

adbridge commented May 5, 2017

This is reliant on #3867 which is targeted for 5.5.0 thus re-targeting this one also for 5.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants