Changeset: b7a6fa14bb1e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b7a6fa14bb1e
Modified Files:
        monetdb5/modules/atoms/mtime.c
        sql/test/BugTracker-2019/Tests/str_to_time.Bug-6791.stable.out
Branch: Nov2019
Log Message:

Fix for bug 6791, ie make sure struct tm is initialized before using it


diffs (128 lines):

diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -342,7 +342,7 @@ static MT_Lock timelock = MT_LOCK_INITIA
 timestamp
 timestamp_fromtime(time_t timeval)
 {
-       struct tm tm, *tmp;
+       struct tm tm = (struct tm) {0}, *tmp;
        date d;
        daytime t;
 
@@ -1705,7 +1705,7 @@ MTIMElocal_timezone_msec(lng *ret)
 #else
        time_t t;
        timestamp lt, gt;
-       struct tm tm, *tmp;
+       struct tm tm = (struct tm) {0}, *tmp;
 
        t = time(NULL);
 #ifdef HAVE_GMTIME_R
@@ -1755,6 +1755,7 @@ MTIMEstr_to_date(date *ret, const char *
                *ret = date_nil;
                return MAL_SUCCEED;
        }
+       tm = (struct tm) {0};
        if (strptime(*s, *format, &tm) == NULL)
                throw(MAL, "mtime.str_to_date", "format '%s', doesn't match 
date '%s'",
                          *format, *s);
@@ -1801,6 +1802,7 @@ MTIMEstr_to_time(daytime *ret, const cha
                *ret = daytime_nil;
                return MAL_SUCCEED;
        }
+       tm = (struct tm) {0};
        if (strptime(*s, *format, &tm) == NULL)
                throw(MAL, "mtime.str_to_time", "format '%s', doesn't match 
time '%s'",
                          *format, *s);
@@ -1824,6 +1826,7 @@ MTIMEtime_to_str(str *ret, const daytime
                return MAL_SUCCEED;
        }
        time_t now = time(NULL);
+       tm = (struct tm) {0};
        /* fill in current date in struct tm */
 #ifdef HAVE_LOCALTIME_R
        localtime_r(&now, &tm);
@@ -1852,12 +1855,13 @@ MTIMEtime_to_str(str *ret, const daytime
 str
 MTIMEstr_to_timestamp(timestamp *ret, const char *const *s, const char *const 
*format)
 {
-       struct tm tm = (struct tm) {0};
+       struct tm tm;
 
        if (GDK_STRNIL(*s) || GDK_STRNIL(*format)) {
                *ret = timestamp_nil;
                return MAL_SUCCEED;
        }
+       tm = (struct tm) {0};
        if (strptime(*s, *format, &tm) == NULL)
                throw(MAL, "mtime.str_to_timestamp",
                          "format '%s', doesn't match timestamp '%s'", *format, 
*s);
diff --git a/sql/test/BugTracker-2019/Tests/str_to_time.Bug-6791.stable.out 
b/sql/test/BugTracker-2019/Tests/str_to_time.Bug-6791.stable.out
--- a/sql/test/BugTracker-2019/Tests/str_to_time.Bug-6791.stable.out
+++ b/sql/test/BugTracker-2019/Tests/str_to_time.Bug-6791.stable.out
@@ -30,6 +30,64 @@ stdout of test 'str_to_time.Bug-6791` in
 % date,        time,   timestamp # type
 % 10,  8,      26 # length
 [ 1987-09-23,  11:40:00,       1987-09-23 11:40:00.000000      ]
+#EXPLAIN SELECT str_to_date('23-09-1987', '%d-%m-%Y') AS "date",
+#       str_to_time('11:40', '%H:%M') AS "time",
+#       str_to_timestamp('23-09-1987 11:40', '%d-%m-%Y %H:%M') AS "timestamp";
+% .explain # table_name
+% mal # name
+% clob # type
+% 269 # length
+function user.s2_0():void;
+    X_7:void := querylog.define("select str_to_date(\\'23-09-1987\\', 
\\'%d-%m-%Y\\') as \"date\",\n str_to_time(\\'11:40\\', \\'%H:%M\\') as 
\"time\",\n str_to_timestamp(\\'23-09-1987 11:40\\', \\'%d-%m-%Y %H:%M\\') as 
\"timestamp\";":str, "default_pipe":str, 34:int);
+    X_21:bat[:str] := bat.new(nil:str);
+    X_27:bat[:int] := bat.new(nil:int);
+    X_25:bat[:int] := bat.new(nil:int);
+    X_24:bat[:str] := bat.new(nil:str);
+    X_23:bat[:str] := bat.new(nil:str);
+    X_28:bat[:str] := bat.append(X_21:bat[:str], ".L2":str);
+    X_30:bat[:str] := bat.append(X_23:bat[:str], "date":str);
+    X_32:bat[:str] := bat.append(X_24:bat[:str], "date":str);
+    X_33:bat[:int] := bat.append(X_25:bat[:int], 0:int);
+    X_35:bat[:int] := bat.append(X_27:bat[:int], 0:int);
+    X_36:bat[:str] := bat.append(X_28:bat[:str], ".L4":str);
+    X_38:bat[:str] := bat.append(X_30:bat[:str], "time":str);
+    X_40:bat[:str] := bat.append(X_32:bat[:str], "time":str);
+    X_41:bat[:int] := bat.append(X_33:bat[:int], 1:int);
+    X_43:bat[:int] := bat.append(X_35:bat[:int], 0:int);
+    X_44:bat[:str] := bat.append(X_36:bat[:str], ".L6":str);
+    X_46:bat[:str] := bat.append(X_38:bat[:str], "timestamp":str);
+    X_48:bat[:str] := bat.append(X_40:bat[:str], "timestamp":str);
+    X_49:bat[:int] := bat.append(X_41:bat[:int], 7:int);
+    X_51:bat[:int] := bat.append(X_43:bat[:int], 0:int);
+    sql.resultSet(X_44:bat[:str], X_46:bat[:str], X_48:bat[:str], 
X_49:bat[:int], X_51:bat[:int], "1987-09-23":date, "11:40:00.000000":daytime, 
"1987-09-23 11:40:00.000000":timestamp);
+end user.s2_0;
+# optimizer.mitosis()
+# optimizer.dataflow()
+#inline               actions= 0 time=1 usec 
+#remap                actions= 0 time=1 usec 
+#costmodel            actions= 1 time=2 usec 
+#coercion             actions= 0 time=2 usec 
+#aliases              actions= 6 time=5 usec 
+#evaluate             actions= 3 time=18 usec 
+#emptybind            actions= 0 time=0 usec 
+#pushselect           actions= 0 time=4 usec 
+#aliases              actions= 3 time=4 usec 
+#mergetable           actions= 0 time=24 usec 
+#deadcode             actions= 1 time=7 usec 
+#aliases              actions= 0 time=0 usec 
+#constants            actions= 0 time=6 usec 
+#commonTerms          actions= 0 time=2 usec 
+#projectionpath       actions= 0 time=2 usec 
+#deadcode             actions= 0 time=5 usec 
+#reorder              actions= 1 time=17 usec 
+#matpack              actions= 0 time=1 usec 
+#multiplex            actions= 0 time=2 usec 
+#profiler             actions= 1 time=1 usec 
+#candidates           actions= 1 time=1 usec 
+#deadcode             actions= 0 time=5 usec 
+#wlc                  actions= 0 time=0 usec 
+#garbagecollector     actions= 1 time=36 usec 
+#total                actions=27 time=221 usec 
 
 # 17:30:27 >  
 # 17:30:27 >  "Done."
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to