Skip to content

Commit 13d0950

Browse files
Copilotdorkmo
andcommitted
Add error checking for fwrite operations per code review
Co-authored-by: dorkmo <[email protected]>
1 parent 40bdb5d commit 13d0950

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

TankAlarm-112025-Client-BluesOpta/TankAlarm-112025-Client-BluesOpta.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,12 @@ static bool saveConfigToFlash(const ClientConfig &cfg) {
784784
return false;
785785
}
786786

787-
fwrite(jsonStr.c_str(), 1, jsonStr.length(), file);
787+
size_t written = fwrite(jsonStr.c_str(), 1, jsonStr.length(), file);
788788
fclose(file);
789+
if (written != jsonStr.length()) {
790+
Serial.println(F("Failed to write config (incomplete)"));
791+
return false;
792+
}
789793
return true;
790794
#else
791795
File file = LittleFS.open(CLIENT_CONFIG_PATH, "w");

TankAlarm-112025-Server-BluesOpta/TankAlarm-112025-Server-BluesOpta.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3013,8 +3013,12 @@ static bool saveConfig(const ServerConfig &cfg) {
30133013
return false;
30143014
}
30153015

3016-
fwrite(jsonStr.c_str(), 1, jsonStr.length(), file);
3016+
size_t written = fwrite(jsonStr.c_str(), 1, jsonStr.length(), file);
30173017
fclose(file);
3018+
if (written != jsonStr.length()) {
3019+
Serial.println(F("Failed to write server config (incomplete)"));
3020+
return false;
3021+
}
30183022
return true;
30193023
#else
30203024
File file = LittleFS.open(SERVER_CONFIG_PATH, "w");

0 commit comments

Comments
 (0)