Skip to content

Commit 4ad4b2a

Browse files
committed
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.
1 parent f2a648d commit 4ad4b2a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

platform/Stream.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616
#include "platform/Stream.h"
17+
#include "platform/mbed_error.h"
18+
#include <errno.h>
1719

1820
namespace mbed {
1921

@@ -23,7 +25,11 @@ Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
2325
char buf[12]; /* :0x12345678 + null byte */
2426
std::sprintf(buf, ":%p", this);
2527
_file = std::fopen(buf, "w+");
26-
mbed_set_unbuffered_stream(_file);
28+
if (_file) {
29+
mbed_set_unbuffered_stream(_file);
30+
} else {
31+
error("Stream obj failure, errno=%d\r\n", errno);
32+
}
2733
}
2834

2935
Stream::~Stream() {

0 commit comments

Comments
 (0)