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 540008 - Change GDate to be immutable like GDateTime; validate additions/subtractions
Change GDate to be immutable like GDateTime; validate additions/subtractions
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: datetime
unspecified
Other All
: Normal normal
: 3.0
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-06-24 17:52 UTC by Morten Welinder
Modified: 2018-05-24 11:27 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Morten Welinder 2008-06-24 17:52:15 UTC
If you subtract a sufficiently large number of months from a date using
g_date_subtract_months, then a critical will be issued, either from

  g_return_if_fail (d->year > years);

or from both of these:

  index = g_date_is_leap_year (d->year) ? 1 : 0;
  g_return_if_fail (g_date_valid (d));

Since this is a data error, not a programming error, and since criticals
will cause crashes with certain settings, g_return_if_fail should not be
used for this purpose.  Instead, an error should be signaled by making
the result invalid.

Think of it this way: How can I use g_date_subtract_months without
risking a crash?  The answer is that I can perform the checks myself,
but at that point I have already done the job of the function.

g_date_subtract_days, g_return_if_fail, and g_date_subtract_years seem to
have the same problem.
Comment 1 Philip Withnall 2018-04-12 10:33:14 UTC
One option is to use GDateTime instead, but that means you need to deal with times too. Really, we need to change the GDate API to deal with immutable instances like GDateTime does (i.e. g_date_time_add_days() returns a new GDateTime instance, or NULL), but that’s going to mean rewriting the API completely.

This is going to have to wait until an API break in GLib.
Comment 2 GNOME Infrastructure Team 2018-05-24 11:27:40 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/147.