Skip to content

Commit 77eca65

Browse files
Fix Print and File incompatible writes w/casts
Print and File have ambiguous resolutions for single-argument write(0)s. Fix by adding explicit methods. A write of any integer will not be a const char* write (i.e. won't write a string) but will instead just write the integer truncated to 8 bits (as makes sense).
1 parent d3a7556 commit 77eca65

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cores/esp8266/FS.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class File : public Stream
5454
// Print methods:
5555
size_t write(uint8_t) override;
5656
size_t write(const uint8_t *buf, size_t size) override;
57+
size_t write(int8_t t) { return write((uint8_t)t); }
58+
size_t write(int16_t t) { return write((uint8_t)(t & 0xff)); }
59+
size_t write(int32_t t) { return write((uint8_t)(t & 0xff)); }
60+
size_t write(uint16_t t) { return write((uint8_t)(t & 0xff)); }
61+
size_t write(uint32_t t) { return write((uint8_t)(t & 0xff)); }
5762

5863
// Stream methods:
5964
int available() override;

tests/host/fs/test_fs.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,12 @@ TEST_CASE("Multisplendored File::writes", "[fs]")
350350
f.write((const uint8_t*)&bigone, 4);
351351
f.close();
352352
REQUIRE(readFileSD("/file.txt") == "aAbbcctheendxyz@@@@");
353+
File g = SD.open("/file.txt", FILE_WRITE);
354+
g.write(0);
355+
g.close();
356+
g = SD.open("/file.txt", FILE_READ);
357+
uint8_t u = 0x66;
358+
g.read(&u, 1);
359+
g.close();
360+
REQUIRE(u == 0);
353361
}

0 commit comments

Comments
 (0)