diff --git a/alog.c b/alog.c index 9abf360..95ae87b 100644 --- a/alog.c +++ b/alog.c @@ -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);