From 4ad4b2a2ef1dbe495bd6eb512cd4f2ab154573c4 Mon Sep 17 00:00:00 2001 From: Laurent MEUNIER Date: Tue, 2 May 2017 17:18:24 +0200 Subject: [PATCH] On small targets there might be memory issues that lead to 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. --- platform/Stream.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/Stream.cpp b/platform/Stream.cpp index 76568712e7..299f9ae8ca 100644 --- a/platform/Stream.cpp +++ b/platform/Stream.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ #include "platform/Stream.h" +#include "platform/mbed_error.h" +#include namespace mbed { @@ -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() {