lib/log: add a check for localtime() failure
localtime() can technically fail and return a NULL pointer. We should handle this case. Change-Id: I5f9d11c5f992453ec3e3804bd17f5d05a863d526 Signed-off-by: Seth Howell <seth.howell@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3245 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
parent
c7d1abba18
commit
8e65bfc7e4
@ -76,6 +76,10 @@ get_timestamp_prefix(char *buf, int buf_size)
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
info = localtime(&ts.tv_sec);
|
||||
usec = ts.tv_nsec / 1000;
|
||||
if (info == NULL) {
|
||||
snprintf(buf, buf_size, "[%s.%06ld] ", "unknown date", usec);
|
||||
return;
|
||||
}
|
||||
|
||||
strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", info);
|
||||
snprintf(buf, buf_size, "[%s.%06ld] ", date, usec);
|
||||
|
Loading…
Reference in New Issue
Block a user