GNOME Bugzilla – Bug 540008
Change GDate to be immutable like GDateTime; validate additions/subtractions
Last modified: 2018-05-24 11:27:40 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.
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.
-- 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.