reduce bad reads
Signed-off-by: Aidan Hahn <aidan@aidanis.online>
This commit is contained in:
parent
b7bedc76ff
commit
08d387cae9
1 changed files with 3 additions and 4 deletions
7
alog.c
7
alog.c
|
|
@ -154,10 +154,9 @@ void alog (
|
||||||
// GET TIMESTAMP
|
// GET TIMESTAMP
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm * p = localtime(&t);
|
struct tm * p = localtime(&t);
|
||||||
int timestamp_size = strftime(NULL, 0, "[%c]", p);
|
char *timestamp = malloc(strftime(NULL, 0, "[%c]", p) + 1);
|
||||||
char *timestamp = malloc(sizeof(char) * (timestamp_size+1));
|
strftime(timestamp, sizeof(timestamp), "[%c]", p);
|
||||||
strftime(timestamp, timestamp_size, "[%c]", p);
|
char *msg_and_timestamp = malloc(sizeof(timestamp) + 1 + (strlen(message) + 1) + 2);
|
||||||
char *msg_and_timestamp = malloc(sizeof(char) * (timestamp_size + strlen(message) + 3));
|
|
||||||
sprintf(msg_and_timestamp, "%s %s\n", timestamp, message);
|
sprintf(msg_and_timestamp, "%s %s\n", timestamp, message);
|
||||||
free(timestamp);
|
free(timestamp);
|
||||||
size = snprintf(NULL, 0, msg_and_timestamp, fmt_list);
|
size = snprintf(NULL, 0, msg_and_timestamp, fmt_list);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue