After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 335731 - g_date_(add|subtract)_(days|months|years) missing overflow checks
g_date_(add|subtract)_(days|months|years) missing overflow checks
Product: glib
Classification: Platform
Component: datetime
Other All
: Normal normal
: ---
Assigned To: gtkdev
: 540012 (view as bug list)
Depends on:
Reported: 2006-03-23 19:30 UTC by Morten Welinder
Modified: 2018-04-13 14:31 UTC
See Also:
GNOME target: ---
GNOME version: ---

gdate: Add overflow precondition checks for g_date_[add|subtract]_*() (1.57 KB, patch)
2018-04-12 17:17 UTC, Philip Withnall
committed Details | Review

Description Morten Welinder 2006-03-23 19:30:54 UTC
All these functions lack checks for overflows.
Comment 1 Philip Withnall 2018-04-12 10:17:05 UTC
*** Bug 540012 has been marked as a duplicate of this bug. ***
Comment 2 Philip Withnall 2018-04-12 17:17:40 UTC
Created attachment 370867 [details] [review]
gdate: Add overflow precondition checks for g_date_[add|subtract]_*()

These turn undefined or hard-to-detect misbehaviour into a well-defined
critical warning and early return.

Signed-off-by: Philip Withnall <>
Comment 3 Emmanuele Bassi (:ebassi) 2018-04-13 13:50:27 UTC
Review of attachment 370867 [details] [review]:

Looks good to me; one minor nitpick, but it's not a blocker.

::: glib/gdate.c
@@ +1722,3 @@
     g_date_update_dmy (d);
+  g_return_if_fail (d->dmy);

I have a personal dislike for using the implicit truthy value of integers; it would be nice to take the chance, and just replace this with an explicit `d->dmy != 0`.

@@ +1813,3 @@
     g_date_update_dmy (d);
+  g_return_if_fail (d->dmy);

Same as above.
Comment 4 Philip Withnall 2018-04-13 14:31:16 UTC
Pushed to master, plus a follow-up commit with the dmy changes. Thanks.

Attachment 370867 [details] pushed as 38080ba - gdate: Add overflow precondition checks for g_date_[add|subtract]_*()