g_timeout_source_new_seconds overflows when given interval > (G_MAXUINT / 1000)
struct _GTimeoutSource
{
GSource source;
guint interval;
gboolean seconds;
};
...
GSource *
g_timeout_source_new_seconds (guint interval)
{
GSource *source = g_source_new (&g_timeout_funcs, sizeof (GTimeoutSource));
GTimeoutSource *timeout_source = (GTimeoutSource *)source;
timeout_source->interval = 1000 * interval;
This overflows, as demonstrated by the following program (which assumes a guint is an uint32_t):
#!/usr/bin/env python3
import math
from gi.repository import GLib
def main():
loop = GLib.MainLoop()
def cb():
print("Should not be reached for 7 weeks")
loop.quit()
return False
# Smallest integral value that will overflow a guint when multiplied by
# 1000, assuming guint == uint32_t
t = math.ceil((2 ** 32) / 1000)
GLib.timeout_add_seconds(t, cb)
loop.run()
if __name__ == '__main__':
main()
This exits within a couple of seconds. (If you replace math.ceil
with math.floor
, it will take almost 2 months to exit.)