Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 81f3c20

Browse files
committed
Fix unsafe assumption that struct timeval.tv_sec is a "long".
It typically is a "long", but it seems possible that on some platforms it wouldn't be. In any case, this silences a compiler warning on OpenBSD (cf buildfarm member curculio). While at it, use snprintf not sprintf. This format string couldn't possibly overrun the supplied buffer, but that doesn't seem like a good reason not to use the safer style. Oversight in commit f828654. Back-patch to 9.6 where that came in.
1 parent ebe5dc9 commit 81f3c20

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/backend/utils/error/elog.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2484,8 +2484,9 @@ log_line_prefix(StringInfo buf, ErrorData *edata)
24842484
saved_timeval_set = true;
24852485
}
24862486

2487-
sprintf(strfbuf, "%ld.%03d", saved_timeval.tv_sec,
2488-
(int) (saved_timeval.tv_usec / 1000));
2487+
snprintf(strfbuf, sizeof(strfbuf), "%ld.%03d",
2488+
(long) saved_timeval.tv_sec,
2489+
(int) (saved_timeval.tv_usec / 1000));
24892490

24902491
if (padding != 0)
24912492
appendStringInfo(buf, "%*s", padding, strfbuf);

0 commit comments

Comments
 (0)