Skip to content

Commit

Permalink
fix localtime_r and tv_usec casting
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Feb 7, 2024
1 parent 2f29d38 commit 17e7b54
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/fmt/text2pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
int re_text2pcap(struct re_printf *pf, struct re_text2pcap *pcap)
{
struct timeval tv;
time_t t = time(NULL);
struct tm *tm = localtime(&t);
char ts[10] = {0};
time_t t = time(NULL);
struct tm tm;
char ts[10] = {0};

if (!pcap)
return EINVAL;
Expand All @@ -20,11 +20,12 @@ int re_text2pcap(struct re_printf *pf, struct re_text2pcap *pcap)
if (!buf)
return EINVAL;

localtime_r(&t, &tm);
gettimeofday(&tv, NULL);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
strftime(ts, sizeof(ts), "%H:%M:%S", &tm);

re_hprintf(pf, "%s %s.%06ld 000000", pcap->in ? "I" : "O", ts,
tv.tv_usec);
(long int)tv.tv_usec);

size_t sz = mbuf_get_left(pcap->mb);
for (size_t i = 0; i < sz; i++) {
Expand Down

0 comments on commit 17e7b54

Please sign in to comment.