@@ -107,8 +107,8 @@ void BoxBattery::_doBatteryTestStep() {
107107 bool batteryLow = isBatteryLow ();
108108 bool batteryCritical = isBatteryCritical ();
109109
110- char * output;
111- asprintf (& output, " %hu;%s;%hu;%hu.%s%hu;%s;%s;" ,
110+ char output[ 5 + 1 + 5 + 1 + 5 + 1 + 3 + 1 + 5 + 5 + 1 + 5 + 1 + 5 + 1 + 1 ] ;
111+ sprintf ( output, " %hu;%s;%hu;%hu.%s%hu;%s;%s;" ,
112112 timeRunning,
113113 (chargerConnected ? " true" : " false" ),
114114 batteryAdcRaw,
@@ -118,7 +118,6 @@ void BoxBattery::_doBatteryTestStep() {
118118 );
119119 Log.info (output);
120120 file.writeString (output);
121- free (output);
122121
123122 file.writeString (" \r\n " );
124123 file.close ();
@@ -133,7 +132,7 @@ void BoxBattery::startBatteryTest() {
133132 _batteryTestStartMillis = millis ();
134133 FileFs file;
135134 if (file.open (_batteryTestFilename, FA_CREATE_ALWAYS | FA_WRITE)) {
136- char * output;
135+ char output[ 26 + 10 + 10 + 1 ] ;
137136
138137 file.writeString (" Timestamp;" );
139138 file.writeString (" Charging;" );
@@ -144,9 +143,8 @@ void BoxBattery::startBatteryTest() {
144143 file.writeString (" Comments" );
145144 file.writeString (" \r\n " );
146145 file.writeString (" 0;;;;;;" );
147- asprintf (& output, " vFactor=%u, vChargerFactor=%u;" , _batteryVoltageFactor, _batteryVoltageChargerFactor);
146+ sprintf ( output, " vFactor=%u, vChargerFactor=%u;" , _batteryVoltageFactor, _batteryVoltageChargerFactor);
148147 file.writeString (output);
149- free (output);
150148 file.writeString (" \r\n " );
151149 file.close ();
152150
@@ -164,11 +162,10 @@ void BoxBattery::stopBatteryTest() {
164162 _doBatteryTestStep ();
165163 FileFs file;
166164 if (file.open (_batteryTestFilename, FA_OPEN_APPEND | FA_WRITE)) {
167- char * output;
165+ char output[ 13 + 5 + 1 ] ;
168166 uint16_t timeRunning = (millis ()-_batteryTestStartMillis) / (1000 *60 );
169- asprintf (& output, " %hu;;;;;;stopped" , timeRunning);
167+ sprintf ( output, " %hu;;;;;;stopped" , timeRunning);
170168 file.writeString (output);
171- free (output);
172169 file.writeString (" \r\n " );
173170 file.close ();
174171 } else {
0 commit comments