Skip to content

Commit 81f7b03

Browse files
committed
Change sprintf to snprintf
1 parent b0a722a commit 81f7b03

13 files changed

+135
-135
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ void beginGNSS()
647647
if (theGNSS.getModuleInfo(1100) == true) // Try to get the module info
648648
{
649649
// Reconstruct the firmware version
650-
sprintf(zedFirmwareVersion, "%s %d.%02d", theGNSS.getFirmwareType(), theGNSS.getFirmwareVersionHigh(), theGNSS.getFirmwareVersionLow());
650+
snprintf(zedFirmwareVersion, sizeof(zedFirmwareVersion), "%s %d.%02d", theGNSS.getFirmwareType(), theGNSS.getFirmwareVersionHigh(), theGNSS.getFirmwareVersionLow());
651651

652652
// Construct the firmware version as uint8_t. Note: will fail above 2.55!
653653
zedFirmwareVersionInt = (theGNSS.getFirmwareVersionHigh() * 100) + theGNSS.getFirmwareVersionLow();
@@ -953,7 +953,7 @@ void beginIdleTasks()
953953

954954
for (int index = 0; index < MAX_CPU_CORES; index++)
955955
{
956-
sprintf(taskName, "IdleTask%d", index);
956+
snprintf(taskName, sizeof(taskName), "IdleTask%d", index);
957957
if (idleTaskHandle[index] == nullptr)
958958
xTaskCreatePinnedToCore(
959959
idleTask,

Firmware/RTK_Surveyor/Bluetooth.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void bluetoothStart()
153153
else if (systemState >= STATE_BASE_NOT_STARTED && systemState <= STATE_BASE_FIXED_TRANSMITTING)
154154
strcpy(stateName, "Base-");
155155

156-
sprintf(deviceName, "%s %s%02X%02X", platformPrefix, stateName, btMACAddress[4], btMACAddress[5]);
156+
snprintf(deviceName, sizeof(deviceName), "%s %s%02X%02X", platformPrefix, stateName, btMACAddress[4], btMACAddress[5]);
157157

158158
// Select Bluetooth setup
159159
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_OFF)
@@ -270,7 +270,7 @@ void bluetoothTest(bool runTest)
270270

271271
//Display Bluetooth MAC address and test results
272272
char macAddress[5];
273-
sprintf(macAddress, "%02X%02X", btMACAddress[4], btMACAddress[5]);
273+
snprintf(macAddress, sizeof(macAddress), "%02X%02X", btMACAddress[4], btMACAddress[5]);
274274
systemPrint("Bluetooth ");
275275
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE)
276276
systemPrint("Low Energy ");

Firmware/RTK_Surveyor/Display.ino

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void updateDisplay()
365365
const uint8_t * rtkMacAddress = getMacAddress();
366366

367367
//Print four characters of MAC
368-
sprintf(macAddress, "%02X%02X", rtkMacAddress[4], rtkMacAddress[5]);
368+
snprintf(macAddress, sizeof(macAddress), "%02X%02X", rtkMacAddress[4], rtkMacAddress[5]);
369369
oled.setFont(QW_FONT_5X7); //Set font to smallest
370370
oled.setCursor(0, 3);
371371
oled.print(macAddress);
@@ -409,7 +409,7 @@ void updateDisplay()
409409
const uint8_t * rtkMacAddress = getMacAddress();
410410

411411
//Print only last two digits of MAC
412-
sprintf(macAddress, "%02X", rtkMacAddress[5]);
412+
snprintf(macAddress, sizeof(macAddress), "%02X", rtkMacAddress[5]);
413413
oled.setFont(QW_FONT_5X7); //Set font to smallest
414414
oled.setCursor(14, 3);
415415
oled.print(macAddress);
@@ -523,9 +523,9 @@ void displaySplash()
523523
yPos = yPos + fontHeight + 7;
524524
char unitFirmware[50];
525525
#ifdef ENABLE_DEVELOPER
526-
sprintf(unitFirmware, "v%d.%d-DEV", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR);
526+
snprintf(unitFirmware, sizeof(unitFirmware), "v%d.%d-DEV", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR);
527527
#else
528-
sprintf(unitFirmware, "v%d.%d", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR);
528+
snprintf(unitFirmware, sizeof(unitFirmware), "v%d.%d", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR);
529529
#endif
530530
printTextCenter(unitFirmware, yPos, QW_FONT_5X7, 1, false);
531531

@@ -1696,11 +1696,11 @@ void displayWiFiConfig()
16961696

16971697
#ifdef COMPILE_WIFI
16981698
if (settings.wifiConfigOverAP == true)
1699-
sprintf(mySSID, "%s", "RTK Config");
1699+
snprintf(mySSID, sizeof(mySSID), "%s", "RTK Config");
17001700
else
1701-
sprintf(mySSID, "%s", WiFi.SSID().c_str());
1701+
snprintf(mySSID, sizeof(mySSID), "%s", WiFi.SSID().c_str());
17021702
#else
1703-
sprintf(mySSID, "%s", "!Compiled");
1703+
snprintf(mySSID, sizeof(mySSID), "%s", "!Compiled");
17041704
#endif
17051705

17061706
char mySSIDFront[displayMaxCharacters + 1]; //1 for null terminator
@@ -1736,7 +1736,7 @@ void displayWiFiConfig()
17361736

17371737
//Convert to string
17381738
char myIP[20] = {'\0'};
1739-
sprintf(myIP, "%d.%d.%d.%d", myIpAddress[0], myIpAddress[1], myIpAddress[2], myIpAddress[3]);
1739+
snprintf(myIP, sizeof(myIP), "%d.%d.%d.%d", myIpAddress[0], myIpAddress[1], myIpAddress[2], myIpAddress[3]);
17401740

17411741
char myIPFront[displayMaxCharacters + 1]; //1 for null terminator
17421742
char myIPBack[displayMaxCharacters + 1]; //1 for null terminator
@@ -1856,7 +1856,7 @@ void displayFirmwareUpdateProgress(int percentComplete)
18561856

18571857
yPos = yPos + fontHeight + 3;
18581858
char temp[50];
1859-
sprintf(temp, "%d%%", percentComplete);
1859+
snprintf(temp, sizeof(temp), "%d%%", percentComplete);
18601860
printTextCenter(temp, yPos, QW_FONT_8X16, 1, false); //text, y, font type, kerning, inverted
18611861

18621862
oled.display(); //Push internal buffer to display
@@ -2014,7 +2014,7 @@ void paintSystemTest()
20142014
//Get the last two digits of MAC
20152015
char macAddress[5];
20162016
const uint8_t * rtkMacAddress = getMacAddress();
2017-
sprintf(macAddress, "%02X%02X", rtkMacAddress[4], rtkMacAddress[5]);
2017+
snprintf(macAddress, sizeof(macAddress), "%02X%02X", rtkMacAddress[4], rtkMacAddress[5]);
20182018

20192019
//Display MAC address
20202020
oled.setCursor(xOffset, yOffset + (5 * charHeight) ); //x, y
@@ -2587,11 +2587,11 @@ void paintKeyProvisionFail(uint16_t displayTime)
25872587
char hardwareID[13];
25882588
const uint8_t * rtkMacAddress = getMacAddress();
25892589

2590-
sprintf(hardwareID, "%02X%02X%02X", rtkMacAddress[0], rtkMacAddress[1], rtkMacAddress[2]);
2590+
snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X", rtkMacAddress[0], rtkMacAddress[1], rtkMacAddress[2]);
25912591
y += fontHeight;
25922592
printTextCenter(hardwareID, y, QW_FONT_5X7, 1, false); //text, y, font type, kerning, inverted
25932593

2594-
sprintf(hardwareID, "%02X%02X%02X", rtkMacAddress[3], rtkMacAddress[4], rtkMacAddress[5]);
2594+
snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X", rtkMacAddress[3], rtkMacAddress[4], rtkMacAddress[5]);
25952595
y += fontHeight;
25962596
printTextCenter(hardwareID, y, QW_FONT_5X7, 1, false); //text, y, font type, kerning, inverted
25972597

Firmware/RTK_Surveyor/Form.ino

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static void handleFirmwareFileUpload(AsyncWebServerRequest * request, String fil
367367
binBytesLastUpdate = binBytesSent;
368368

369369
char bytesSentMsg[100];
370-
sprintf(bytesSentMsg, "%'d bytes sent", binBytesSent);
370+
snprintf(bytesSentMsg, sizeof(bytesSentMsg), "%'d bytes sent", binBytesSent);
371371

372372
systemPrintf("bytesSentMsg: %s\r\n", bytesSentMsg);
373373

@@ -446,7 +446,7 @@ void createSettingsString(char* newSettings)
446446
stringRecord(newSettings, "platformPrefix", platformPrefix);
447447

448448
char apRtkFirmwareVersion[86];
449-
sprintf(apRtkFirmwareVersion, "v%d.%d-%s", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR, __DATE__);
449+
snprintf(apRtkFirmwareVersion, sizeof(apRtkFirmwareVersion), "v%d.%d-%s", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR, __DATE__);
450450
stringRecord(newSettings, "rtkFirmwareVersion", apRtkFirmwareVersion);
451451

452452
char apZedPlatform[50];
@@ -456,11 +456,11 @@ void createSettingsString(char* newSettings)
456456
strcpy(apZedPlatform, "ZED-F9R");
457457

458458
char apZedFirmwareVersion[80];
459-
sprintf(apZedFirmwareVersion, "%s Firmware: %s", apZedPlatform, zedFirmwareVersion);
459+
snprintf(apZedFirmwareVersion, sizeof(apZedFirmwareVersion), "%s Firmware: %s", apZedPlatform, zedFirmwareVersion);
460460
stringRecord(newSettings, "zedFirmwareVersion", apZedFirmwareVersion);
461461

462462
char apDeviceBTID[30];
463-
sprintf(apDeviceBTID, "Device Bluetooth ID: %02X%02X", btMACAddress[4], btMACAddress[5]);
463+
snprintf(apDeviceBTID, sizeof(apDeviceBTID), "Device Bluetooth ID: %02X%02X", btMACAddress[4], btMACAddress[5]);
464464
stringRecord(newSettings, "deviceBTID", apDeviceBTID);
465465

466466
//GNSS Config
@@ -544,19 +544,19 @@ void createSettingsString(char* newSettings)
544544

545545
//L-Band
546546
char hardwareID[13];
547-
sprintf(hardwareID, "%02X%02X%02X%02X%02X%02X", lbandMACAddress[0], lbandMACAddress[1], lbandMACAddress[2], lbandMACAddress[3], lbandMACAddress[4], lbandMACAddress[5]); //Get ready for JSON
547+
snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X", lbandMACAddress[0], lbandMACAddress[1], lbandMACAddress[2], lbandMACAddress[3], lbandMACAddress[4], lbandMACAddress[5]); //Get ready for JSON
548548
stringRecord(newSettings, "hardwareID", hardwareID);
549549

550550
char apDaysRemaining[20];
551551
if (strlen(settings.pointPerfectCurrentKey) > 0)
552552
{
553553
#ifdef COMPILE_L_BAND
554554
uint8_t daysRemaining = daysFromEpoch(settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1);
555-
sprintf(apDaysRemaining, "%d", daysRemaining);
555+
snprintf(apDaysRemaining, sizeof(apDaysRemaining), "%d", daysRemaining);
556556
#endif
557557
}
558558
else
559-
sprintf(apDaysRemaining, "No Keys");
559+
snprintf(apDaysRemaining, sizeof(apDaysRemaining), "No Keys");
560560

561561
stringRecord(newSettings, "daysRemaining", apDaysRemaining);
562562

@@ -576,8 +576,8 @@ void createSettingsString(char* newSettings)
576576
stringRecord(newSettings, "profileNumber", profileNumber);
577577
for (int index = 0; index < MAX_PROFILE_COUNT; index++)
578578
{
579-
sprintf(tagText, "profile%dName", index);
580-
sprintf(nameText, "%d: %s", index + 1, profileNames[index]);
579+
snprintf(tagText, sizeof(tagText), "profile%dName", index);
580+
snprintf(nameText, sizeof(nameText), "%d: %s", index + 1, profileNames[index]);
581581
stringRecord(newSettings, tagText, nameText);
582582
}
583583
//stringRecord(newSettings, "activeProfiles", activeProfiles);
@@ -611,7 +611,7 @@ void createSettingsString(char* newSettings)
611611

612612
//Radio / ESP-Now settings
613613
char radioMAC[18]; //Send radio MAC
614-
sprintf(radioMAC, "%02X:%02X:%02X:%02X:%02X:%02X",
614+
snprintf(radioMAC, sizeof(radioMAC), "%02X:%02X:%02X:%02X:%02X:%02X",
615615
wifiMACAddress[0],
616616
wifiMACAddress[1],
617617
wifiMACAddress[2],
@@ -624,8 +624,8 @@ void createSettingsString(char* newSettings)
624624
stringRecord(newSettings, "espnowPeerCount", settings.espnowPeerCount);
625625
for (int index = 0; index < settings.espnowPeerCount; index++)
626626
{
627-
sprintf(tagText, "peerMAC%d", index);
628-
sprintf(nameText, "%02X:%02X:%02X:%02X:%02X:%02X",
627+
snprintf(tagText, sizeof(tagText), "peerMAC%d", index);
628+
snprintf(nameText, sizeof(nameText), "%02X:%02X:%02X:%02X:%02X:%02X",
629629
settings.espnowPeers[index][0],
630630
settings.espnowPeers[index][1],
631631
settings.espnowPeers[index][2],
@@ -649,15 +649,15 @@ void createSettingsString(char* newSettings)
649649
trim(stationInfo); //Remove trailing whitespace
650650
//log_d("ECEF SD station %d - found: %s", index, stationInfo);
651651
replaceCharacter(stationInfo, ',', ' '); //Change all , to ' ' for easier parsing on the JS side
652-
sprintf(tagText, "stationECEF%d", index);
652+
snprintf(tagText, sizeof(tagText), "stationECEF%d", index);
653653
stringRecord(newSettings, tagText, stationInfo);
654654
}
655655
else if (getFileLineLFS(stationCoordinateECEFFileName, index, stationInfo, sizeof(stationInfo)) == true) //fileName, lineNumber, array, arraySize
656656
{
657657
trim(stationInfo); //Remove trailing whitespace
658658
//log_d("ECEF LFS station %d - found: %s", index, stationInfo);
659659
replaceCharacter(stationInfo, ',', ' '); //Change all , to ' ' for easier parsing on the JS side
660-
sprintf(tagText, "stationECEF%d", index);
660+
snprintf(tagText, sizeof(tagText), "stationECEF%d", index);
661661
stringRecord(newSettings, tagText, stationInfo);
662662
}
663663
else
@@ -678,15 +678,15 @@ void createSettingsString(char* newSettings)
678678
trim(stationInfo); //Remove trailing whitespace
679679
//log_d("Geo SD station %d - found: %s", index, stationInfo);
680680
replaceCharacter(stationInfo, ',', ' '); //Change all , to ' ' for easier parsing on the JS side
681-
sprintf(tagText, "stationGeodetic%d", index);
681+
snprintf(tagText, sizeof(tagText), "stationGeodetic%d", index);
682682
stringRecord(newSettings, tagText, stationInfo);
683683
}
684684
else if (getFileLineLFS(stationCoordinateGeodeticFileName, index, stationInfo, sizeof(stationInfo)) == true) //fileName, lineNumber, array, arraySize
685685
{
686686
trim(stationInfo); //Remove trailing whitespace
687687
//log_d("Geo LFS station %d - found: %s", index, stationInfo);
688688
replaceCharacter(stationInfo, ',', ' '); //Change all , to ' ' for easier parsing on the JS side
689-
sprintf(tagText, "stationGeodetic%d", index);
689+
snprintf(tagText, sizeof(tagText), "stationGeodetic%d", index);
690690
stringRecord(newSettings, tagText, stationInfo);
691691
}
692692
else
@@ -699,10 +699,10 @@ void createSettingsString(char* newSettings)
699699
//Add WiFi credential table
700700
for (int x = 0 ; x < MAX_WIFI_NETWORKS ; x++)
701701
{
702-
sprintf(tagText, "wifiNetwork%dSSID", x);
702+
snprintf(tagText, sizeof(tagText), "wifiNetwork%dSSID", x);
703703
stringRecord(newSettings, tagText, settings.wifiNetworks[x].ssid);
704704

705-
sprintf(tagText, "wifiNetwork%dPassword", x);
705+
snprintf(tagText, sizeof(tagText), "wifiNetwork%dPassword", x);
706706
stringRecord(newSettings, tagText, settings.wifiNetworks[x].password);
707707
}
708708

@@ -1013,26 +1013,26 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
10131013
//We got a version number, now determine if it's newer or not
10141014
char currentVersion[20];
10151015
if (enableRCFirmware == false)
1016-
sprintf(currentVersion, "%d.%d", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR);
1016+
snprintf(currentVersion, sizeof(currentVersion), "%d.%d", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR);
10171017
else
1018-
sprintf(currentVersion, "%d.%d-%s", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR, __DATE__);
1018+
snprintf(currentVersion, sizeof(currentVersion), "%d.%d-%s", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR, __DATE__);
10191019

10201020
if (isReportedVersionNewer(reportedVersion, currentVersion) == true)
10211021
{
10221022
log_d("New version detected");
1023-
sprintf(newVersionCSV, "newFirmwareVersion,%s,", reportedVersion);
1023+
snprintf(newVersionCSV, sizeof(newVersionCSV), "newFirmwareVersion,%s,", reportedVersion);
10241024
}
10251025
else
10261026
{
10271027
log_d("No new firmware available");
1028-
sprintf(newVersionCSV, "newFirmwareVersion,CURRENT,");
1028+
snprintf(newVersionCSV, sizeof(newVersionCSV), "newFirmwareVersion,CURRENT,");
10291029
}
10301030
}
10311031
else
10321032
{
10331033
//Failed to get version number
10341034
log_d("Sending error to AP config page");
1035-
sprintf(newVersionCSV, "newFirmwareVersion,ERROR,");
1035+
snprintf(newVersionCSV, sizeof(newVersionCSV), "newFirmwareVersion,ERROR,");
10361036
}
10371037

10381038
websocket->textAll(newVersionCSV);
@@ -1062,7 +1062,7 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
10621062
for (int x = 0 ; x < MAX_WIFI_NETWORKS ; x++)
10631063
{
10641064
char tempString[100]; //wifiNetwork0Password=parachutes
1065-
sprintf(tempString, "wifiNetwork%dSSID", x);
1065+
snprintf(tempString, sizeof(tempString), "wifiNetwork%dSSID", x);
10661066
if (strcmp(settingName, tempString) == 0)
10671067
{
10681068
strcpy(settings.wifiNetworks[x].ssid, settingValueStr);
@@ -1071,7 +1071,7 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
10711071
}
10721072
else
10731073
{
1074-
sprintf(tempString, "wifiNetwork%dPassword", x);
1074+
snprintf(tempString, sizeof(tempString), "wifiNetwork%dPassword", x);
10751075
if (strcmp(settingName, tempString) == 0)
10761076
{
10771077
strcpy(settings.wifiNetworks[x].password, settingValueStr);
@@ -1088,7 +1088,7 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
10881088
for (int x = 0 ; x < MAX_CONSTELLATIONS ; x++)
10891089
{
10901090
char tempString[50]; //ubxConstellationsSBAS
1091-
sprintf(tempString, "ubxConstellations%s", settings.ubxConstellations[x].textName);
1091+
snprintf(tempString, sizeof(tempString), "ubxConstellations%s", settings.ubxConstellations[x].textName);
10921092

10931093
if (strcmp(settingName, tempString) == 0)
10941094
{
@@ -1126,29 +1126,29 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
11261126
void stringRecord(char* settingsCSV, const char *id, int settingValue)
11271127
{
11281128
char record[100];
1129-
sprintf(record, "%s,%d,", id, settingValue);
1129+
snprintf(record, sizeof(record), "%s,%d,", id, settingValue);
11301130
strcat(settingsCSV, record);
11311131
}
11321132

11331133
//Add record with uint32_t
11341134
void stringRecord(char* settingsCSV, const char *id, uint32_t settingValue)
11351135
{
11361136
char record[100];
1137-
sprintf(record, "%s,%d,", id, settingValue);
1137+
snprintf(record, sizeof(record), "%s,%d,", id, settingValue);
11381138
strcat(settingsCSV, record);
11391139
}
11401140

11411141
//Add record with double
11421142
void stringRecord(char* settingsCSV, const char *id, double settingValue, int decimalPlaces)
11431143
{
11441144
char format[10];
1145-
sprintf(format, "%%0.%dlf", decimalPlaces); //Create '%0.09lf'
1145+
snprintf(format, sizeof(format), "%%0.%dlf", decimalPlaces); //Create '%0.09lf'
11461146

11471147
char formattedValue[20];
1148-
sprintf(formattedValue, format, settingValue);
1148+
snprintf(formattedValue, sizeof(formattedValue), format, settingValue);
11491149

11501150
char record[100];
1151-
sprintf(record, "%s,%s,", id, formattedValue);
1151+
snprintf(record, sizeof(record), "%s,%s,", id, formattedValue);
11521152
strcat(settingsCSV, record);
11531153
}
11541154

@@ -1162,23 +1162,23 @@ void stringRecord(char* settingsCSV, const char *id, bool settingValue)
11621162
strcpy(temp, "false");
11631163

11641164
char record[100];
1165-
sprintf(record, "%s,%s,", id, temp);
1165+
snprintf(record, sizeof(record), "%s,%s,", id, temp);
11661166
strcat(settingsCSV, record);
11671167
}
11681168

11691169
//Add record with string
11701170
void stringRecord(char* settingsCSV, const char *id, char* settingValue)
11711171
{
11721172
char record[100];
1173-
sprintf(record, "%s,%s,", id, settingValue);
1173+
snprintf(record, sizeof(record), "%s,%s,", id, settingValue);
11741174
strcat(settingsCSV, record);
11751175
}
11761176

11771177
//Add record with uint64_t
11781178
void stringRecord(char* settingsCSV, const char *id, uint64_t settingValue)
11791179
{
11801180
char record[100];
1181-
sprintf(record, "%s,%lld,", id, settingValue);
1181+
snprintf(record, sizeof(record), "%s,%lld,", id, settingValue);
11821182
strcat(settingsCSV, record);
11831183
}
11841184

@@ -1333,13 +1333,13 @@ String stringHumanReadableSize(uint64_t bytes)
13331333
else cardSize = bytes / 1024.0 / 1024.0 / 1024.0; //GB
13341334

13351335
if (strcmp(suffix, "GB") == 0)
1336-
sprintf(readableSize, "%0.1f %s", cardSize, suffix); //Print decimal portion
1336+
snprintf(readableSize, sizeof(readableSize), "%0.1f %s", cardSize, suffix); //Print decimal portion
13371337
else if (strcmp(suffix, "MB") == 0)
1338-
sprintf(readableSize, "%0.1f %s", cardSize, suffix); //Print decimal portion
1338+
snprintf(readableSize, sizeof(readableSize), "%0.1f %s", cardSize, suffix); //Print decimal portion
13391339
else if (strcmp(suffix, "KB") == 0)
1340-
sprintf(readableSize, "%0.1f %s", cardSize, suffix); //Print decimal portion
1340+
snprintf(readableSize, sizeof(readableSize), "%0.1f %s", cardSize, suffix); //Print decimal portion
13411341
else
1342-
sprintf(readableSize, "%.0f %s", cardSize, suffix); //Don't print decimal portion
1342+
snprintf(readableSize, sizeof(readableSize), "%.0f %s", cardSize, suffix); //Don't print decimal portion
13431343

13441344
return String(readableSize);
13451345
}

0 commit comments

Comments
 (0)