mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-08 03:42:12 +03:00
log.c: Fix current_timestring()
The second argument to strftime() should be the size of the buffer as per the manpage. The previous code used size - 1 as the second argument. This commit modifies that behaviour to use buffer size as the second argument of strftime(). Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
904c3e024c
commit
0e756306f0
@@ -59,7 +59,7 @@ static int current_timestring(int hires, char *buf, size_t len)
|
||||
{
|
||||
char tbuf[64];
|
||||
struct timeval tv;
|
||||
struct tm *tm;
|
||||
struct tm *tm = NULL;
|
||||
time_t t;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
@@ -71,10 +71,10 @@ static int current_timestring(int hires, char *buf, size_t len)
|
||||
}
|
||||
|
||||
if (hires) {
|
||||
strftime(tbuf, sizeof(tbuf) - 1, "%Y/%m/%d %H:%M:%S", tm);
|
||||
strftime(tbuf, sizeof(tbuf), "%Y/%m/%d %H:%M:%S", tm);
|
||||
snprintf(buf, len, "%s.%06ld", tbuf, (long)tv.tv_usec);
|
||||
} else {
|
||||
strftime(tbuf, sizeof(tbuf) - 1, "%Y/%m/%d %H:%M:%S", tm);
|
||||
strftime(tbuf, sizeof(tbuf), "%Y/%m/%d %H:%M:%S", tm);
|
||||
snprintf(buf, len, "%s", tbuf);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user