@@ -168,8 +168,10 @@ void menuPointPerfectKeys()
168
168
}
169
169
170
170
// Given a GPS Epoch, return a DD/MM/YYYY string
171
- char *printDateFromGPSEpoch (long long gpsEpoch)
171
+ const char *printDateFromGPSEpoch (long long gpsEpoch)
172
172
{
173
+ static char response[strlen (" 01/01/1010" ) + 1 ]; // Make room for terminator
174
+
173
175
uint16_t keyGPSWeek;
174
176
uint32_t keyGPSToW;
175
177
epochToWeekToW (gpsEpoch, &keyGPSWeek, &keyGPSToW);
@@ -179,35 +181,35 @@ char *printDateFromGPSEpoch(long long gpsEpoch)
179
181
long expYear;
180
182
gpsWeekToWToDate (keyGPSWeek, keyGPSToW, &expDay, &expMonth, &expYear);
181
183
182
- char *response = (char *)malloc (strlen (" 01/01/1010" ));
183
-
184
184
sprintf (response, " %02ld/%02ld/%ld" , expDay, expMonth, expYear);
185
- return (response);
185
+ return (( const char *) response);
186
186
}
187
187
188
188
// Given a Unix Epoch, return a DD/MM/YYYY string
189
189
// https://www.epochconverter.com/programming/c
190
- char *printDateFromUnixEpoch (long long unixEpoch)
190
+ const char *printDateFromUnixEpoch (long long unixEpoch)
191
191
{
192
- char *buf = (char *)malloc (strlen (" 01/01/2023" ) + 1 ); // Make room for terminator
192
+ static char response[strlen (" 01/01/2023" ) + 1 ]; // Make room for terminator
193
+
193
194
time_t rawtime = unixEpoch;
194
195
195
196
struct tm ts;
196
197
ts = *localtime (&rawtime);
197
198
198
199
// Format time, "dd/mm/yyyy"
199
- strftime (buf , strlen (" 01/01/2023" ) + 1 , " %d/%m/%Y" , &ts);
200
- return (buf );
200
+ strftime (response , strlen (" 01/01/2023" ) + 1 , " %d/%m/%Y" , &ts);
201
+ return (( const char *)response );
201
202
}
202
203
203
204
// Given a duration in ms, print days
204
- char *printDaysFromDuration (long long duration)
205
+ const char *printDaysFromDuration (long long duration)
205
206
{
207
+ static char response[strlen (" 99.99" ) + 1 ]; // Make room for terminator
208
+
206
209
float days = duration / (1000.0 * 60 * 60 * 24 ); // Convert ms to days
207
210
208
- char *response = (char *)malloc (strlen (" 34.9" ) + 1 ); // Make room for terminator
209
211
sprintf (response, " %0.2f" , days);
210
- return (response);
212
+ return (( const char *) response);
211
213
}
212
214
213
215
// Connect to 'home' WiFi and then ThingStream API. This will attach this unique device to the ThingStream network.
@@ -954,8 +956,8 @@ bool pointperfectUpdateKeys()
954
956
void mqttCallback (int messageSize)
955
957
{
956
958
#ifdef COMPILE_WIFI
957
- static uint32_t messageLength;
958
- static byte *message;
959
+ static uint32_t messageLength = 0 ;
960
+ static byte *message = nullptr ;
959
961
960
962
do
961
963
{
@@ -967,7 +969,7 @@ void mqttCallback(int messageSize)
967
969
if (messageLength < messageSize)
968
970
{
969
971
// Free the previous message buffer
970
- if (message)
972
+ if (message != nullptr )
971
973
{
972
974
free (message);
973
975
message = nullptr ;
0 commit comments