From 630b5a8165aab25d99989916f36412a0414068be Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 28 Mar 2017 18:41:43 -0700 Subject: 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 --- text2pcap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'text2pcap.c') 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 */ -- cgit v1.2.3