Remove null byte at the end of fdopen's faux filename

pull/4974/head
Fahrzin Hemmati 2017-08-10 21:14:12 -07:00 committed by adbridge
parent a92440b74f
commit 3feef6f5bf
1 changed files with 2 additions and 3 deletions

View File

@ -827,11 +827,10 @@ void mbed_set_unbuffered_stream(std::FILE *_file) {
std::FILE *mbed_fdopen(FileHandle *fh, const char *mode)
{
// This is to avoid scanf(buf, ":%.4s", fh) and the bloat it brings.
char buf[2 + sizeof(fh) + 1]; /* :(pointer) + null byte */
MBED_STATIC_ASSERT(sizeof(buf) == 7, "Pointers should be 4 bytes.");
char buf[1 + sizeof(fh)]; /* :(pointer) */
MBED_STATIC_ASSERT(sizeof(buf) == 5, "Pointers should be 4 bytes.");
buf[0] = ':';
memcpy(buf + 1, &fh, sizeof(fh));
buf[1 + sizeof(fh)] = '\0';
std::FILE *stream = std::fopen(buf, mode);
/* newlib-nano doesn't appear to ever call _isatty itself, so