Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda48a52

Browse files
authored
Fix File::readString to work with binary data (#8742)
Previously, File::readString used a C-style string as an intermediatebuffer via the String += operator. This treats a NUL byte as aterminator, making this function work incorrectly if the File containsbinary data.This commit switches the function to use String::concat, which doesn'ttreat NUL bytes any differently (and is a bit faster, because it doesn'tneed to use strlen).
1 parent3c62531 commitda48a52

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

‎cores/esp8266/FS.cpp‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,15 @@ File File::openNextFile() {
173173
return _fakeDir->openFile("r");
174174
}
175175

176-
StringFile::readString()
177-
{
176+
StringFile::readString() {
178177
String ret;
179178
ret.reserve(size() -position());
180-
char temp[256+1];
181-
int countRead =readBytes(temp,sizeof(temp)-1);
182-
while (countRead >0)
183-
{
184-
temp[countRead] =0;
185-
ret += temp;
186-
countRead =readBytes(temp,sizeof(temp)-1);
187-
}
179+
uint8_t temp[256];
180+
int countRead;
181+
do {
182+
countRead =read(temp,sizeof(temp));
183+
ret.concat((constchar*)temp, countRead);
184+
}while (countRead >0);
188185
return ret;
189186
}
190187

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp