mirror of https://github.com/arendst/Tasmota.git
Merge pull request #5420 from laurentdong/Code-review
Code review: Copy string with strlcpy() instead of snprintf()
This commit is contained in:
commit
aec3842bee
|
@ -229,7 +229,7 @@ char* GetOtaUrl(char *otaurl, size_t otaurl_size)
|
||||||
snprintf_P(otaurl, otaurl_size, Settings.ota_url, ESP.getChipId());
|
snprintf_P(otaurl, otaurl_size, Settings.ota_url, ESP.getChipId());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
snprintf(otaurl, otaurl_size, Settings.ota_url);
|
strlcpy(otaurl, Settings.ota_url, otaurl_size);
|
||||||
}
|
}
|
||||||
return otaurl;
|
return otaurl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -672,7 +672,7 @@ void SerialSendRaw(char *codes)
|
||||||
int size = strlen(codes);
|
int size = strlen(codes);
|
||||||
|
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
snprintf(stemp, sizeof(stemp), codes);
|
strlcpy(stemp, codes, sizeof(stemp));
|
||||||
code = strtol(stemp, &p, 16);
|
code = strtol(stemp, &p, 16);
|
||||||
Serial.write(code);
|
Serial.write(code);
|
||||||
size -= 2;
|
size -= 2;
|
||||||
|
|
|
@ -765,10 +765,10 @@ bool MqttCommand(void)
|
||||||
if (data_len > 0) {
|
if (data_len > 0) {
|
||||||
char *mqtt_part = strtok(dataBuf, " ");
|
char *mqtt_part = strtok(dataBuf, " ");
|
||||||
if (mqtt_part) {
|
if (mqtt_part) {
|
||||||
snprintf(stemp1, sizeof(stemp1), mqtt_part);
|
strlcpy(stemp1, mqtt_part, sizeof(stemp1));
|
||||||
mqtt_part = strtok(NULL, " ");
|
mqtt_part = strtok(NULL, " ");
|
||||||
if (mqtt_part) {
|
if (mqtt_part) {
|
||||||
snprintf(mqtt_data, sizeof(mqtt_data), mqtt_part);
|
strlcpy(mqtt_data, mqtt_part, sizeof(mqtt_data));
|
||||||
} else {
|
} else {
|
||||||
mqtt_data[0] = '\0';
|
mqtt_data[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ bool SerialBridgeCommand(void)
|
||||||
int size = strlen(XdrvMailbox.data);
|
int size = strlen(XdrvMailbox.data);
|
||||||
|
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
snprintf(stemp, sizeof(stemp), codes);
|
strlcpy(stemp, codes, sizeof(stemp));
|
||||||
code = strtol(stemp, &p, 16);
|
code = strtol(stemp, &p, 16);
|
||||||
SerialBridgeSerial->write(code); // "AA004566" as hex values
|
SerialBridgeSerial->write(code); // "AA004566" as hex values
|
||||||
size -= 2;
|
size -= 2;
|
||||||
|
|
|
@ -385,7 +385,7 @@ bool TimerCommand(void)
|
||||||
uint8_t sign = 0;
|
uint8_t sign = 0;
|
||||||
char time_str[10];
|
char time_str[10];
|
||||||
|
|
||||||
snprintf(time_str, sizeof(time_str), root[parm_uc]);
|
strlcpy(time_str, root[parm_uc], sizeof(time_str));
|
||||||
const char *substr = strtok(time_str, ":");
|
const char *substr = strtok(time_str, ":");
|
||||||
if (substr != NULL) {
|
if (substr != NULL) {
|
||||||
if (strchr(substr, '-')) {
|
if (strchr(substr, '-')) {
|
||||||
|
|
|
@ -218,7 +218,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule)
|
||||||
}
|
}
|
||||||
#endif // USE_TIMERS and USE_SUNRISE
|
#endif // USE_TIMERS and USE_SUNRISE
|
||||||
rule_param.toUpperCase();
|
rule_param.toUpperCase();
|
||||||
snprintf(rule_svalue, sizeof(rule_svalue), rule_param.c_str());
|
strlcpy(rule_svalue, rule_param.c_str(), sizeof(rule_svalue));
|
||||||
|
|
||||||
int temp_value = GetStateNumber(rule_svalue);
|
int temp_value = GetStateNumber(rule_svalue);
|
||||||
if (temp_value > -1) {
|
if (temp_value > -1) {
|
||||||
|
@ -365,7 +365,7 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved)
|
||||||
#endif // USE_TIMERS and USE_SUNRISE
|
#endif // USE_TIMERS and USE_SUNRISE
|
||||||
|
|
||||||
char command[commands.length() +1];
|
char command[commands.length() +1];
|
||||||
snprintf(command, sizeof(command), commands.c_str());
|
strlcpy(command, commands.c_str(), sizeof(command));
|
||||||
|
|
||||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("RUL: %s performs \"%s\""), event_trigger.c_str(), command);
|
AddLog_P2(LOG_LEVEL_INFO, PSTR("RUL: %s performs \"%s\""), event_trigger.c_str(), command);
|
||||||
|
|
||||||
|
|
|
@ -226,7 +226,7 @@ void MatrixOnOff(void)
|
||||||
|
|
||||||
void MatrixDrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uint8_t flag)
|
void MatrixDrawStringAt(uint16_t x, uint16_t y, char *str, uint16_t color, uint8_t flag)
|
||||||
{
|
{
|
||||||
snprintf(mtx_buffer, MTX_MAX_SCREEN_BUFFER, str);
|
strlcpy(mtx_buffer, str, MTX_MAX_SCREEN_BUFFER);
|
||||||
mtx_mode = x &1; // Use x for selecting scroll up (0) or scroll left (1)
|
mtx_mode = x &1; // Use x for selecting scroll up (0) or scroll left (1)
|
||||||
mtx_loop = y &1; // Use y for selecting no loop (0) or loop (1)
|
mtx_loop = y &1; // Use y for selecting no loop (0) or loop (1)
|
||||||
if (!mtx_state) { mtx_state = 1; }
|
if (!mtx_state) { mtx_state = 1; }
|
||||||
|
|
|
@ -539,7 +539,7 @@ void BmpShow(bool json)
|
||||||
float bmp_pressure = ConvertPressure(bmp_sensors[bmp_idx].bmp_pressure);
|
float bmp_pressure = ConvertPressure(bmp_sensors[bmp_idx].bmp_pressure);
|
||||||
|
|
||||||
char name[10];
|
char name[10];
|
||||||
snprintf(name, sizeof(name), bmp_sensors[bmp_idx].bmp_name);
|
strlcpy(name, bmp_sensors[bmp_idx].bmp_name, sizeof(name));
|
||||||
if (bmp_count > 1) {
|
if (bmp_count > 1) {
|
||||||
snprintf_P(name, sizeof(name), PSTR("%s-%02X"), name, bmp_sensors[bmp_idx].bmp_address); // BMXXXX-XX
|
snprintf_P(name, sizeof(name), PSTR("%s-%02X"), name, bmp_sensors[bmp_idx].bmp_address); // BMXXXX-XX
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue