Skip to content

Commit 8543279

Browse files
authored
Merge pull request #4259 from LMESTM/fix_Stream_issue687
Add error check in Stream constructor
2 parents e2469ec + 4ad4b2a commit 8543279

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)