Skip to content

Commit

Permalink
Check for localtime() failing.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
guyharris committed Apr 17, 2017
1 parent ca29ec9 commit f63ad23
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ui/text_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) +
Expand All @@ -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;

Expand Down

0 comments on commit f63ad23

Please sign in to comment.