reduce bad reads

Signed-off-by: Aidan Hahn <aidan@aidanis.online>
This commit is contained in:
Aidan Hahn 2022-03-07 00:15:11 -08:00
parent b7bedc76ff
commit 08d387cae9
No known key found for this signature in database
GPG key ID: 327711E983899316

7
alog.c
View file

@ -154,10 +154,9 @@ void alog (
// GET TIMESTAMP
time_t t = time(NULL);
struct tm * p = localtime(&t);
int timestamp_size = strftime(NULL, 0, "[%c]", p);
char *timestamp = malloc(sizeof(char) * (timestamp_size+1));
strftime(timestamp, timestamp_size, "[%c]", p);
char *msg_and_timestamp = malloc(sizeof(char) * (timestamp_size + strlen(message) + 3));
char *timestamp = malloc(strftime(NULL, 0, "[%c]", p) + 1);
strftime(timestamp, sizeof(timestamp), "[%c]", p);
char *msg_and_timestamp = malloc(sizeof(timestamp) + 1 + (strlen(message) + 1) + 2);
sprintf(msg_and_timestamp, "%s %s\n", timestamp, message);
free(timestamp);
size = snprintf(NULL, 0, msg_and_timestamp, fmt_list);