From deb4f08cb21d8a5306b325d811c3448b46ad18d0 Mon Sep 17 00:00:00 2001 From: Pascal Quantin Date: Fri, 4 Jan 2013 14:56:27 +0000 Subject: Fix https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8105 : Allow use of huges values for localtime / ctime / gmtime with MSVC 2008 or later svn path=/trunk/; revision=46930 --- wiretap/k12text.l | 12 ++++++++---- wiretap/ngsniffer.c | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'wiretap') diff --git a/wiretap/k12text.l b/wiretap/k12text.l index 13f197dfb1..71a74cb70c 100644 --- a/wiretap/k12text.l +++ b/wiretap/k12text.l @@ -375,6 +375,7 @@ k12text_dump(wtap_dumper *wdh _U_, const struct wtap_pkthdr *phdr, guint ns; guint ms; gboolean ret; + struct tm *tmp; str_enc = NULL; for(i=0; encaps[i].s; i++) { @@ -397,16 +398,19 @@ k12text_dump(wtap_dumper *wdh _U_, const struct wtap_pkthdr *phdr, ms = phdr->ts.nsecs / 1000000; ns = (phdr->ts.nsecs - (1000000*ms))/1000; -#ifdef _MSC_VER +#if (defined _WIN32) && (_MSC_VER < 1500) /* calling gmtime() on MSVC 2005 with huge values causes it to crash */ /* XXX - find the exact value that still does work */ /* XXX - using _USE_32BIT_TIME_T might be another way to circumvent this problem */ if (phdr->ts.secs > 2000000000) - g_snprintf(p, 90, "+---------+---------------+----------+\r\nXX:XX:XX,"); + tmp = NULL; else #endif - strftime(p, 90, "+---------+---------------+----------+\r\n%H:%M:%S,", - gmtime(&phdr->ts.secs)); + tmp = gmtime(&phdr->ts.secs); + if (tmp == NULL) + g_snprintf(p, 90, "+---------+---------------+----------+\r\nXX:XX:XX,"); + else + strftime(p, 90, "+---------+---------------+----------+\r\n%H:%M:%S,", tmp); wl = strlen(p); p += wl; left -= wl; diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index b0145565b2..a738c80a39 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -2127,7 +2127,7 @@ ngsniffer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, date. */ if (ngsniffer->first_frame) { ngsniffer->first_frame=FALSE; -#ifdef _MSC_VER +#if (defined _WIN32) && (_MSC_VER < 1500) /* calling localtime() on MSVC 2005 with huge values causes it to crash */ /* XXX - find the exact value that still does work */ /* XXX - using _USE_32BIT_TIME_T might be another way to circumvent this problem */ -- cgit v1.2.1