Change GDate to be immutable like GDateTime; validate additions/subtractions
Submitted by Morten Welinder
Link to original bug (#540008)
Description
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.