From 8ebe3f680e9f343a13bfcaaa2e17745b701ec0c8 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 3 Jan 2014 01:40:17 +0100 Subject: [PATCH] alarm: skip timed out alarms when inserting in procalarm() (thanks erik) from erik quanstros 9fans post: i think the list insertion code needs a single-read test that f->alarm != 0. to prevent the 0 from acting like a fencepost. e.g. trying to insert -10 into list -40 -30 0 -20. if(alarms.head) { l = &alarms.head; for(f = *l; f; f = f->palarm) { >> fw = f->alarm; >> if(fw != 0 && (long)(fw - when) >= 0) { up->palarm = f; *l = up; goto done; } l = &f->palarm; } *l = up; } --- sys/src/9/port/alarm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/src/9/port/alarm.c b/sys/src/9/port/alarm.c index 8fb45be94..320b66e60 100644 --- a/sys/src/9/port/alarm.c +++ b/sys/src/9/port/alarm.c @@ -88,7 +88,8 @@ procalarm(ulong time) if(alarms.head) { l = &alarms.head; for(f = *l; f; f = f->palarm) { - if((long)(f->alarm - when) >= 0) { + time = f->alarm; + if(time != 0 && (long)(time - when) >= 0) { up->palarm = f; *l = up; goto done;