Skip to content

Commit

Permalink
fixed buffer length
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-k-chang committed Apr 24, 2024
1 parent 0990ef0 commit 8498220
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <stdarg.h>
#include "log.h"

static char curr_time[32];
#define TIME_LEN 64

static char curr_time[TIME_LEN];
static int log2screen = 1;
static int log2file;
static char log_file_name[128];
Expand Down Expand Up @@ -37,9 +39,9 @@ static char *print_time()
gettimeofday(&tv, NULL);
now = tv.tv_sec;
nowtm = localtime(&now);
char timebuf[32];
strftime(timebuf, 32, "%Y-%m-%d %H:%M:%S", nowtm);
snprintf(curr_time, 32, "%s %06ld",timebuf, (long)tv.tv_usec);
char timebuf[TIME_LEN];
strftime(timebuf, TIME_LEN, "%Y-%m-%d %H:%M:%S", nowtm);
snprintf(curr_time, TIME_LEN + 32, "%s %06ld",timebuf, (long)tv.tv_usec);
return curr_time;
}

Expand Down

0 comments on commit 8498220

Please sign in to comment.