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

Fix File::readString to work with binary data#8742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mcspr merged 1 commit intoesp8266:masterfromelipsitz:fix-file-readstring
Dec 6, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix File::readString to work with binary data
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).
  • Loading branch information
@elipsitz
elipsitz committedDec 6, 2022
commitbd67b186d01270558bd9c5d53a3599ac58c89aad
17 changes: 7 additions & 10 deletionscores/esp8266/FS.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -173,18 +173,15 @@ File File::openNextFile() {
return _fakeDir->openFile("r");
}

String File::readString()
{
String File::readString() {
String ret;
ret.reserve(size() - position());
char temp[256+1];
int countRead = readBytes(temp, sizeof(temp)-1);
while (countRead > 0)
{
temp[countRead] = 0;
ret += temp;
countRead = readBytes(temp, sizeof(temp)-1);
}
uint8_t temp[256];
int countRead;
do {
countRead = read(temp, sizeof(temp));
ret.concat((const char*)temp, countRead);
} while (countRead > 0);
return ret;
}

Expand Down

[8]ページ先頭

©2009-2026 Movatter.jp