@@ -367,7 +367,7 @@ static void handleFirmwareFileUpload(AsyncWebServerRequest * request, String fil
367
367
binBytesLastUpdate = binBytesSent;
368
368
369
369
char bytesSentMsg[100 ];
370
- sprintf (bytesSentMsg, " %'d bytes sent" , binBytesSent);
370
+ snprintf (bytesSentMsg, sizeof (bytesSentMsg) , " %'d bytes sent" , binBytesSent);
371
371
372
372
systemPrintf (" bytesSentMsg: %s\r\n " , bytesSentMsg);
373
373
@@ -446,7 +446,7 @@ void createSettingsString(char* newSettings)
446
446
stringRecord (newSettings, " platformPrefix" , platformPrefix);
447
447
448
448
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__);
450
450
stringRecord (newSettings, " rtkFirmwareVersion" , apRtkFirmwareVersion);
451
451
452
452
char apZedPlatform[50 ];
@@ -456,11 +456,11 @@ void createSettingsString(char* newSettings)
456
456
strcpy (apZedPlatform, " ZED-F9R" );
457
457
458
458
char apZedFirmwareVersion[80 ];
459
- sprintf (apZedFirmwareVersion, " %s Firmware: %s" , apZedPlatform, zedFirmwareVersion);
459
+ snprintf (apZedFirmwareVersion, sizeof (apZedFirmwareVersion) , " %s Firmware: %s" , apZedPlatform, zedFirmwareVersion);
460
460
stringRecord (newSettings, " zedFirmwareVersion" , apZedFirmwareVersion);
461
461
462
462
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 ]);
464
464
stringRecord (newSettings, " deviceBTID" , apDeviceBTID);
465
465
466
466
// GNSS Config
@@ -544,19 +544,19 @@ void createSettingsString(char* newSettings)
544
544
545
545
// L-Band
546
546
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
548
548
stringRecord (newSettings, " hardwareID" , hardwareID);
549
549
550
550
char apDaysRemaining[20 ];
551
551
if (strlen (settings.pointPerfectCurrentKey ) > 0 )
552
552
{
553
553
#ifdef COMPILE_L_BAND
554
554
uint8_t daysRemaining = daysFromEpoch (settings.pointPerfectNextKeyStart + settings.pointPerfectNextKeyDuration + 1 );
555
- sprintf (apDaysRemaining, " %d" , daysRemaining);
555
+ snprintf (apDaysRemaining, sizeof (apDaysRemaining) , " %d" , daysRemaining);
556
556
#endif
557
557
}
558
558
else
559
- sprintf (apDaysRemaining, " No Keys" );
559
+ snprintf (apDaysRemaining, sizeof (apDaysRemaining) , " No Keys" );
560
560
561
561
stringRecord (newSettings, " daysRemaining" , apDaysRemaining);
562
562
@@ -576,8 +576,8 @@ void createSettingsString(char* newSettings)
576
576
stringRecord (newSettings, " profileNumber" , profileNumber);
577
577
for (int index = 0 ; index < MAX_PROFILE_COUNT; index ++)
578
578
{
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 ]);
581
581
stringRecord (newSettings, tagText, nameText);
582
582
}
583
583
// stringRecord(newSettings, "activeProfiles", activeProfiles);
@@ -611,7 +611,7 @@ void createSettingsString(char* newSettings)
611
611
612
612
// Radio / ESP-Now settings
613
613
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" ,
615
615
wifiMACAddress[0 ],
616
616
wifiMACAddress[1 ],
617
617
wifiMACAddress[2 ],
@@ -624,8 +624,8 @@ void createSettingsString(char* newSettings)
624
624
stringRecord (newSettings, " espnowPeerCount" , settings.espnowPeerCount );
625
625
for (int index = 0 ; index < settings.espnowPeerCount ; index ++)
626
626
{
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" ,
629
629
settings.espnowPeers [index ][0 ],
630
630
settings.espnowPeers [index ][1 ],
631
631
settings.espnowPeers [index ][2 ],
@@ -649,15 +649,15 @@ void createSettingsString(char* newSettings)
649
649
trim (stationInfo); // Remove trailing whitespace
650
650
// log_d("ECEF SD station %d - found: %s", index, stationInfo);
651
651
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 );
653
653
stringRecord (newSettings, tagText, stationInfo);
654
654
}
655
655
else if (getFileLineLFS (stationCoordinateECEFFileName, index , stationInfo, sizeof (stationInfo)) == true ) // fileName, lineNumber, array, arraySize
656
656
{
657
657
trim (stationInfo); // Remove trailing whitespace
658
658
// log_d("ECEF LFS station %d - found: %s", index, stationInfo);
659
659
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 );
661
661
stringRecord (newSettings, tagText, stationInfo);
662
662
}
663
663
else
@@ -678,15 +678,15 @@ void createSettingsString(char* newSettings)
678
678
trim (stationInfo); // Remove trailing whitespace
679
679
// log_d("Geo SD station %d - found: %s", index, stationInfo);
680
680
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 );
682
682
stringRecord (newSettings, tagText, stationInfo);
683
683
}
684
684
else if (getFileLineLFS (stationCoordinateGeodeticFileName, index , stationInfo, sizeof (stationInfo)) == true ) // fileName, lineNumber, array, arraySize
685
685
{
686
686
trim (stationInfo); // Remove trailing whitespace
687
687
// log_d("Geo LFS station %d - found: %s", index, stationInfo);
688
688
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 );
690
690
stringRecord (newSettings, tagText, stationInfo);
691
691
}
692
692
else
@@ -699,10 +699,10 @@ void createSettingsString(char* newSettings)
699
699
// Add WiFi credential table
700
700
for (int x = 0 ; x < MAX_WIFI_NETWORKS ; x++)
701
701
{
702
- sprintf (tagText, " wifiNetwork%dSSID" , x);
702
+ snprintf (tagText, sizeof (tagText) , " wifiNetwork%dSSID" , x);
703
703
stringRecord (newSettings, tagText, settings.wifiNetworks [x].ssid );
704
704
705
- sprintf (tagText, " wifiNetwork%dPassword" , x);
705
+ snprintf (tagText, sizeof (tagText) , " wifiNetwork%dPassword" , x);
706
706
stringRecord (newSettings, tagText, settings.wifiNetworks [x].password );
707
707
}
708
708
@@ -1013,26 +1013,26 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
1013
1013
// We got a version number, now determine if it's newer or not
1014
1014
char currentVersion[20 ];
1015
1015
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);
1017
1017
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__);
1019
1019
1020
1020
if (isReportedVersionNewer (reportedVersion, currentVersion) == true )
1021
1021
{
1022
1022
log_d (" New version detected" );
1023
- sprintf (newVersionCSV, " newFirmwareVersion,%s," , reportedVersion);
1023
+ snprintf (newVersionCSV, sizeof (newVersionCSV) , " newFirmwareVersion,%s," , reportedVersion);
1024
1024
}
1025
1025
else
1026
1026
{
1027
1027
log_d (" No new firmware available" );
1028
- sprintf (newVersionCSV, " newFirmwareVersion,CURRENT," );
1028
+ snprintf (newVersionCSV, sizeof (newVersionCSV) , " newFirmwareVersion,CURRENT," );
1029
1029
}
1030
1030
}
1031
1031
else
1032
1032
{
1033
1033
// Failed to get version number
1034
1034
log_d (" Sending error to AP config page" );
1035
- sprintf (newVersionCSV, " newFirmwareVersion,ERROR," );
1035
+ snprintf (newVersionCSV, sizeof (newVersionCSV) , " newFirmwareVersion,ERROR," );
1036
1036
}
1037
1037
1038
1038
websocket->textAll (newVersionCSV);
@@ -1062,7 +1062,7 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
1062
1062
for (int x = 0 ; x < MAX_WIFI_NETWORKS ; x++)
1063
1063
{
1064
1064
char tempString[100 ]; // wifiNetwork0Password=parachutes
1065
- sprintf (tempString, " wifiNetwork%dSSID" , x);
1065
+ snprintf (tempString, sizeof (tempString) , " wifiNetwork%dSSID" , x);
1066
1066
if (strcmp (settingName, tempString) == 0 )
1067
1067
{
1068
1068
strcpy (settings.wifiNetworks [x].ssid , settingValueStr);
@@ -1071,7 +1071,7 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
1071
1071
}
1072
1072
else
1073
1073
{
1074
- sprintf (tempString, " wifiNetwork%dPassword" , x);
1074
+ snprintf (tempString, sizeof (tempString) , " wifiNetwork%dPassword" , x);
1075
1075
if (strcmp (settingName, tempString) == 0 )
1076
1076
{
1077
1077
strcpy (settings.wifiNetworks [x].password , settingValueStr);
@@ -1088,7 +1088,7 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
1088
1088
for (int x = 0 ; x < MAX_CONSTELLATIONS ; x++)
1089
1089
{
1090
1090
char tempString[50 ]; // ubxConstellationsSBAS
1091
- sprintf (tempString, " ubxConstellations%s" , settings.ubxConstellations [x].textName );
1091
+ snprintf (tempString, sizeof (tempString) , " ubxConstellations%s" , settings.ubxConstellations [x].textName );
1092
1092
1093
1093
if (strcmp (settingName, tempString) == 0 )
1094
1094
{
@@ -1126,29 +1126,29 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
1126
1126
void stringRecord (char * settingsCSV, const char *id, int settingValue)
1127
1127
{
1128
1128
char record[100 ];
1129
- sprintf (record, " %s,%d," , id, settingValue);
1129
+ snprintf (record, sizeof (record) , " %s,%d," , id, settingValue);
1130
1130
strcat (settingsCSV, record);
1131
1131
}
1132
1132
1133
1133
// Add record with uint32_t
1134
1134
void stringRecord (char * settingsCSV, const char *id, uint32_t settingValue)
1135
1135
{
1136
1136
char record[100 ];
1137
- sprintf (record, " %s,%d," , id, settingValue);
1137
+ snprintf (record, sizeof (record) , " %s,%d," , id, settingValue);
1138
1138
strcat (settingsCSV, record);
1139
1139
}
1140
1140
1141
1141
// Add record with double
1142
1142
void stringRecord (char * settingsCSV, const char *id, double settingValue, int decimalPlaces)
1143
1143
{
1144
1144
char format[10 ];
1145
- sprintf (format, " %%0.%dlf" , decimalPlaces); // Create '%0.09lf'
1145
+ snprintf (format, sizeof (format) , " %%0.%dlf" , decimalPlaces); // Create '%0.09lf'
1146
1146
1147
1147
char formattedValue[20 ];
1148
- sprintf (formattedValue, format, settingValue);
1148
+ snprintf (formattedValue, sizeof (formattedValue) , format, settingValue);
1149
1149
1150
1150
char record[100 ];
1151
- sprintf (record, " %s,%s," , id, formattedValue);
1151
+ snprintf (record, sizeof (record) , " %s,%s," , id, formattedValue);
1152
1152
strcat (settingsCSV, record);
1153
1153
}
1154
1154
@@ -1162,23 +1162,23 @@ void stringRecord(char* settingsCSV, const char *id, bool settingValue)
1162
1162
strcpy (temp, " false" );
1163
1163
1164
1164
char record[100 ];
1165
- sprintf (record, " %s,%s," , id, temp);
1165
+ snprintf (record, sizeof (record) , " %s,%s," , id, temp);
1166
1166
strcat (settingsCSV, record);
1167
1167
}
1168
1168
1169
1169
// Add record with string
1170
1170
void stringRecord (char * settingsCSV, const char *id, char * settingValue)
1171
1171
{
1172
1172
char record[100 ];
1173
- sprintf (record, " %s,%s," , id, settingValue);
1173
+ snprintf (record, sizeof (record) , " %s,%s," , id, settingValue);
1174
1174
strcat (settingsCSV, record);
1175
1175
}
1176
1176
1177
1177
// Add record with uint64_t
1178
1178
void stringRecord (char * settingsCSV, const char *id, uint64_t settingValue)
1179
1179
{
1180
1180
char record[100 ];
1181
- sprintf (record, " %s,%lld," , id, settingValue);
1181
+ snprintf (record, sizeof (record) , " %s,%lld," , id, settingValue);
1182
1182
strcat (settingsCSV, record);
1183
1183
}
1184
1184
@@ -1333,13 +1333,13 @@ String stringHumanReadableSize(uint64_t bytes)
1333
1333
else cardSize = bytes / 1024.0 / 1024.0 / 1024.0 ; // GB
1334
1334
1335
1335
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
1337
1337
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
1339
1339
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
1341
1341
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
1343
1343
1344
1344
return String (readableSize);
1345
1345
}
0 commit comments