diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-03-28 18:41:43 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-03-29 01:42:14 +0000 |
commit | 630b5a8165aab25d99989916f36412a0414068be (patch) | |
tree | d298b259d86c5effb27821875858912ba2668187 /text2pcap.c | |
parent | 1bea950b7a7934fe7bed7719a0ed99321785f7d6 (diff) |
Check for localtime() failing.
It "shouldn't happen", but at least this squelches a Coverity complaint,
CID 1394503.
Change-Id: I40af10d47c1d1b026f6b40ef68b139e6bf246109
Reviewed-on: https://code.wireshark.org/review/20774
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'text2pcap.c')
-rw-r--r-- | text2pcap.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/text2pcap.c b/text2pcap.c index 848c213c79..87a3e90680 100644 --- a/text2pcap.c +++ b/text2pcap.c @@ -1469,6 +1469,7 @@ parse_options (int argc, char *argv[]) {"version", no_argument, NULL, 'v'}, {0, 0, 0, 0 } }; + struct tm *now_tm; #ifdef _WIN32 arg_list_utf_16to8(argc, argv); @@ -1833,8 +1834,17 @@ parse_options (int argc, char *argv[]) } ts_sec = time(0); /* initialize to current time */ - /* We trust the OS to return a time after 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"); + return EXIT_FAILURE; + } + timecode_default = *now_tm; timecode_default.tm_isdst = -1; /* Unknown for now, depends on time given to the strptime() function */ /* Display summary of our state */ |