changeset 757:d26bfc4cd1f0

Visual Studio 2008's runtime is crazy sensitive. I put in a bunch of parameter checks to make sure nothing out of the ordinary ever ever gets passed to strftime().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 17 Mar 2011 16:42:53 +0000
parents ef17c8079f1d
children 842bc671eaa7
files win/dw.c
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/win/dw.c	Thu Mar 17 15:34:05 2011 +0000
+++ b/win/dw.c	Thu Mar 17 16:42:53 2011 +0000
@@ -7663,14 +7663,15 @@
       struct tm curtm;
       CDATE cdate = *((CDATE *)data);
 
-
+	  memset(&curtm, 0, sizeof(struct tm));
+	  
 	  /* Safety check... zero dates are crashing
 	   * Visual Studio 2008. -Brian
 	   */
-	  if(cdate.year > 1900)
+	  if(cdate.year > 1900 && cdate.year < 2100)
 	  {
-		  curtm.tm_mday = cdate.day;
-		  curtm.tm_mon = cdate.month > 0 ? cdate.month - 1 : 0;
+		  curtm.tm_mday = (cdate.day >= 0 && cdate.day < 32) ? cdate.day : 1;
+		  curtm.tm_mon = (cdate.month > 0 && cdate.month < 13) ? cdate.month - 1 : 0;
 		  curtm.tm_year = cdate.year - 1900;
 
 		  strftime(textbuffer, 100, "%x", &curtm);
@@ -7688,9 +7689,9 @@
       struct tm curtm;
       CTIME ctime = *((CTIME *)data);
 
-      curtm.tm_hour = ctime.hours;
-      curtm.tm_min = ctime.minutes;
-      curtm.tm_sec = ctime.seconds;
+	  curtm.tm_hour = (ctime.hours >= 0 && ctime.hours < 24) ? ctime.hours : 0;
+      curtm.tm_min = (ctime.minutes >= 0 && ctime.minutes < 60) ? ctime.minutes : 0;
+      curtm.tm_sec = (ctime.seconds >= 0 && ctime.seconds < 60) ? ctime.seconds : 0;
 
       strftime(textbuffer, 100, "%X", &curtm);