]> saetta.ns0.it Git - libzakutils/commitdiff
Possible glib bug: valid date with values out of range.
authorAndrea Zagli <azagli@libero.it>
Mon, 1 May 2017 10:40:08 +0000 (12:40 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 1 May 2017 10:40:08 +0000 (12:40 +0200)
The function g_date_time_new_local return a valida date also
if passed values for month/day are out of range.

src/datetime.c

index cad5883b99badd77bf3b2cfd89126a0d61009c04..1c3eb4aa5d667c98b4ba361c1a8fe02196ab2c01 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -497,6 +497,19 @@ GDateTime
                                                     hour,
                                                     minute,
                                                     seconds);
+
+                       /* possible glib bug
+                        * returns a valid date also if day/month values are out of range */
+                       if (g_date_time_get_year (ret) != year
+                           || g_date_time_get_month (ret) != month
+                           || g_date_time_get_day_of_month (ret) != day
+                           || g_date_time_get_hour (ret) != hour
+                           || g_date_time_get_minute (ret) != minute
+                           || g_date_time_get_seconds (ret) != seconds)
+                               {
+                                       g_date_time_unref (ret);
+                                       ret = NULL;
+                               }
                }
 
        return ret;