Skip to content

Commit afb383d

Browse files
authored
Fix undefined behavior in bootloader SHA256 hex conversion
Change char to unsigned char to avoid undefined behavior during right-shift operation.
1 parent 1f92ac1 commit afb383d

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

wled00/ota_update.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ String getBootloaderSHA256Hex() {
453453
String result;
454454
result.reserve(65);
455455
for (int i = 0; i < 32; i++) {
456-
char b1 = bootloaderSHA256Cache[i];
457-
char b2 = b1 >> 4;
456+
unsigned char b1 = bootloaderSHA256Cache[i];
457+
unsigned char b2 = b1 >> 4; // bugfix: right-shift on signed char is undefined behaviour
458458
b1 &= 0x0F;
459459
b1 += '0'; b2 += '0';
460460
if (b1 > '9') b1 += 39;
@@ -780,4 +780,4 @@ void handleBootloaderOTAData(AsyncWebServerRequest *request, size_t index, uint8
780780
// -------------------------------------
781781

782782

783-
#endif
783+
#endif

0 commit comments

Comments
 (0)