Skip to content

Commit

Permalink
On small targets there might be memory issues that lead to
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LMESTM committed May 2, 2017
1 parent f2a648d commit 4ad4b2a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion platform/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
#include "platform/Stream.h"
#include "platform/mbed_error.h"
#include <errno.h>

namespace mbed {

Expand All @@ -23,7 +25,11 @@ 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) {
mbed_set_unbuffered_stream(_file);
} else {
error("Stream obj failure, errno=%d\r\n", errno);
}
}

Stream::~Stream() {
Expand Down

0 comments on commit 4ad4b2a

Please sign in to comment.