fix theoretical overflow with sprintf

This commit is contained in:
gilex-dev 2023-11-13 22:33:19 +01:00
parent 900a1d9af2
commit 782fe8cf04
2 changed files with 8 additions and 29 deletions

View File

@ -3,23 +3,6 @@
void reload_home() // generates current time and changes variables in home_html void reload_home() // generates current time and changes variables in home_html
{ {
char time_current[3][3] = {"", "", ""};
if (myTime.hour() < 10) {
sprintf(time_current[0], "0%d", myTime.hour());
} else {
sprintf(time_current[0], "%d", myTime.hour());
}
if (myTime.minute() < 10) {
sprintf(time_current[1], "0%d", myTime.minute());
} else {
sprintf(time_current[1], "%d", myTime.minute());
}
if (myTime.second() < 10) {
sprintf(time_current[2], "0%d", myTime.second());
} else {
sprintf(time_current[2], "%d", myTime.second());
}
sprintf(home_html, "<!DOCTYPE html>\ sprintf(home_html, "<!DOCTYPE html>\
<html lang='de'>\ <html lang='de'>\
<head>\ <head>\
@ -80,7 +63,7 @@ top: 2px;\
<body>\ <body>\
<div class='wrapper_main'>\ <div class='wrapper_main'>\
<h1>Übersicht</h1>\ <h1>Übersicht</h1>\
<h2>Uhrzeit: <span>%s:%s:%s</span></h2>\ <h2>Uhrzeit: <span>%02d:%02d:%02d</span></h2>\
<div class='wrapper_form'>\ <div class='wrapper_form'>\
<div>\ <div>\
<span>Ventil 1: </span>\ <span>Ventil 1: </span>\
@ -93,7 +76,7 @@ top: 2px;\
</div>\ </div>\
</body>\ </body>\
</html>", </html>",
time_current[0], time_current[1], time_current[2], stat[0]); myTime.hour(), myTime.minute(), myTime.second(), stat[0]);
} }
void reload_settings() { void reload_settings() {

View File

@ -1,7 +1,7 @@
const char SSID[] = ""; const char SSID[] = "";
const char PASSWORD[] = ""; const char PASSWORD[] = "";
const char version[] = " 0.8.2"; const char version[] = " 0.8.3";
#include "globalvars.h" #include "globalvars.h"
#include <Arduino.h> #include <Arduino.h>
#include <DallasTemperature.h> #include <DallasTemperature.h>
@ -156,11 +156,7 @@ void load_EEPROM() {
unsigned int EEPROM_Addr = 0; unsigned int EEPROM_Addr = 0;
for (unsigned int i0 = 0; i0 < 8; i0++) { for (unsigned int i0 = 0; i0 < 8; i0++) {
for (unsigned int i = 0; i < 8; i++) { for (unsigned int i = 0; i < 8; i++) {
if (EEPROM.read(EEPROM_Addr) < 10) { sprintf(time_all[i0][i], "%02d", EEPROM.read(EEPROM_Addr));
sprintf(time_all[i0][i], "0%d", EEPROM.read(EEPROM_Addr));
} else {
sprintf(time_all[i0][i], "%d", EEPROM.read(EEPROM_Addr));
}
EEPROM_Addr += 4; EEPROM_Addr += 4;
yield(); yield();
} }
@ -194,10 +190,10 @@ void handleTime() {
server.arg(args[arg])[1]}; server.arg(args[arg])[1]};
char buff_m[2][2] = {server.arg(args[arg])[3], char buff_m[2][2] = {server.arg(args[arg])[3],
server.arg(args[arg])[4]}; server.arg(args[arg])[4]};
sprintf(time_all[arg * 2][server.arg("rule").toInt()], "%s", sprintf(time_all[arg * 2][server.arg("rule").toInt()], "%s%s",
buff_h); buff_h[0], buff_h[1]);
sprintf(time_all[arg * 2 + 1][server.arg("rule").toInt()], "%s", sprintf(time_all[arg * 2 + 1][server.arg("rule").toInt()],
buff_m); "%s%s", buff_m[0], buff_m[1]);
EEPROM.put(server.arg("rule").toInt() * 4 + arg * 64, EEPROM.put(server.arg("rule").toInt() * 4 + arg * 64,
atoi(time_all[arg * 2][server.arg("rule").toInt()])); atoi(time_all[arg * 2][server.arg("rule").toInt()]));