Skip to content

gtimezone: Fix assertion failure when called with a huge offset

Philip Withnall requested to merge pwithnall/glib:2620-timezone-offset into main

This looks like a regression from commit 3356934d, but prior to that commit there was always an assertion failure when calling g_time_zone_new_offset() with an offset which is too large (such as 44 hours), ever since the function was added in commit cf24867b.

It would be ideal if we could return a NULL timezone to indicate the error, but that’s not part of the API for g_time_zone_new_offset(), so we have to go with the dated and not-ideal approach of returning the UTC timezone and letting the caller figure it out.

Another potential approach would be to reduce the offset modulo 24 hours. This makes the error less easily detectable than if returning UTC, though, and still returns an invalid result: +44:00 is not the same timezone as +20:00 (it’s one day further ahead).

Add a unit test.

Signed-off-by: Philip Withnall pwithnall@endlessos.org

Fixes: #2620 (closed)

Closes #2620 (closed)

Edited by Philip Withnall

Merge request reports