Fix https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8105 :
authorpascal <pascal@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 4 Jan 2013 14:56:27 +0000 (14:56 +0000)
committerpascal <pascal@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 4 Jan 2013 14:56:27 +0000 (14:56 +0000)
Allow use of huges values for localtime / ctime / gmtime with MSVC 2008 or later

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@46930 f5534014-38df-0310-8fa8-9805f1628bb7

capinfos.c
editcap.c
epan/to_str.c
ui/gtk/summary_dlg.c
wiretap/k12text.l
wiretap/ngsniffer.c

index a799be22bf5ecc02c9c4d4c22e8225caf272fe06..96d7de998ab89c7e115bf5716e84a7316f8b392c 100644 (file)
@@ -395,7 +395,7 @@ time_string(time_t timer, capture_info *cf_info, gboolean want_lf)
       g_snprintf(time_string_buf, 20, "%lu%s", (unsigned long)timer, lf);
       return time_string_buf;
     } else {
-#ifdef _MSC_VER
+#if (defined _WIN32) && (_MSC_VER < 1500)
       /* calling localtime(), and thus ctime(), 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 */
index cad88565062e40cdd94f181753bacb6ccdcba7c9..870536fc50a8edcf79e1b2b2b58cd98f9868f660 100644 (file)
--- a/editcap.c
+++ b/editcap.c
@@ -149,7 +149,7 @@ abs_time_to_str_with_sec_resolution(const struct wtap_nstime *abs_time)
     struct tm *tmp;
     gchar *buf = g_malloc(16);
 
-#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 */
index e25675647bb815031e040f2e38848a9db02c4354..601b898548cd997023e62fc52dc3fcdb4bafac9c 100644 (file)
@@ -571,7 +571,7 @@ abs_time_to_str(const nstime_t *abs_time, const absolute_time_display_e fmt,
         const char *zonename = "???";
         gchar *buf = NULL;
 
-#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 */
@@ -655,7 +655,7 @@ abs_time_secs_to_str(const time_t abs_time, const absolute_time_display_e fmt,
         const char *zonename = "???";
         gchar *buf = NULL;
 
-#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 */
index 648663825df5b65e03eb04b7577ef18f19ea8886..078a3210ebf57e647f517d1c69185765810229b4 100644 (file)
@@ -116,7 +116,7 @@ time_to_string(char *string_buff, gulong string_buff_size, time_t ti_time)
 {
   struct tm *ti_tm;
 
-#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 */
index 13f197dfb1f5757bcf1b9ed513dace6ec7dd2ae0..71a74cb70c57595cb520471de1e7a93274d6721c 100644 (file)
@@ -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;
index b0145565b2843b6f94e15b7f2028e51dd735fb78..a738c80a39b5834e0b73f3a718865b012229e823 100644 (file)
@@ -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 */