diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-04-17 00:48:20 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-04-17 07:48:56 +0000 |
commit | f63ad23ef9036a60e78e5efd45936aae1705d5ac (patch) | |
tree | dcc33d134b3c9c8b1dca7f1444900cc1963a5b22 /ui/text_import.c | |
parent | ca29ec9e77ce0422562727187e3d2946f6ec2d6c (diff) |
Check for localtime() failing.
It "shouldn't happen", but at least this squelches a Coverity complaint,
CID 1398224.
Change-Id: I9555f71a50574e9386a3c96d52143d838f7f121f
Reviewed-on: https://code.wireshark.org/review/21160
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui/text_import.c')
-rw-r--r-- | ui/text_import.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ui/text_import.c b/ui/text_import.c index 0536028a5b..812d34e64b 100644 --- a/ui/text_import.c +++ b/ui/text_import.c @@ -921,6 +921,7 @@ text_import(text_import_info_t *info) { yyscan_t scanner; int ret; + struct tm *now_tm; packet_buf = (guint8 *)g_malloc(sizeof(HDR_ETHERNET) + sizeof(HDR_IP) + sizeof(HDR_SCTP) + sizeof(HDR_DATA_CHUNK) + @@ -938,8 +939,17 @@ text_import(text_import_info_t *info) packet_start = 0; packet_preamble_len = 0; ts_sec = time(0); /* initialize to current time */ - /* We trust the OS not to provide a time before the Epoch. */ - timecode_default = *localtime(&ts_sec); + now_tm = localtime(&ts_sec); + if (now_tm == NULL) { + /* + * This shouldn't happen - on UN*X, this should Just Work, and + * on Windows, it won't work if ts_sec is before the Epoch, + * but it's long after 1970, so.... + */ + fprintf(stderr, "localtime(right now) failed\n"); + exit(-1); + } + timecode_default = *now_tm; timecode_default.tm_isdst = -1; /* Unknown for now, depends on time given to the strptime() function */ ts_usec = 0; |