[libgda] DataHanlder: return NULL on invalid time



commit 89a5667d0f58716723443ab31b9017f7380c9ecc
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Mar 18 13:14:23 2020 -0600

    DataHanlder: return NULL on invalid time

 libgda/gda-util.c                  | 13 ++++++++++---
 libgda/handlers/gda-handler-time.c |  2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/libgda/gda-util.c b/libgda/gda-util.c
index 0fc9ca0d4..7d49a0daf 100644
--- a/libgda/gda-util.c
+++ b/libgda/gda-util.c
@@ -3257,12 +3257,16 @@ _parse_iso8601_time (const gchar *value, gchar sep, glong timezone, const char *
                }
                for (; *endptr; endptr++);
        }
-       GdaTime *dt = (GdaTime*) g_date_time_new (tz, 1978, 1, 1, h, m, seconds);
+       GDateTime *dt = g_date_time_new (tz, 1978, 1, 1, h, m, seconds);
 
        g_time_zone_unref (tz);
 
        *out_endptr = endptr;
-       return dt;
+  if (dt != NULL) {
+    return (GdaTime*)  dt;
+  }
+
+       return NULL;
 }
 
 /**
@@ -3286,7 +3290,10 @@ gda_parse_iso8601_time (const gchar *value)
   dt = g_date_time_new_from_iso8601 (str, tz);
   g_time_zone_unref (tz);
   g_free (str);
-  return (GdaTime*) dt;
+  if (dt != NULL) {
+    return (GdaTime*) dt;
+  }
+  return NULL;
 }
 
 /**
diff --git a/libgda/handlers/gda-handler-time.c b/libgda/handlers/gda-handler-time.c
index 312ba1fea..954d50e2a 100644
--- a/libgda/handlers/gda-handler-time.c
+++ b/libgda/handlers/gda-handler-time.c
@@ -792,7 +792,7 @@ gda_handler_time_get_value_from_locale (GdaDataHandler *iface, const gchar *sql,
                }
        }
        else
-               g_assert_not_reached ();
+               return NULL;
 
        return value;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]