From a6af536be0d264d9e7d0e26fd07cd822d1c0331a Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 30 Jan 2017 16:56:03 +0000 Subject: bugfix: ftrigr_update() could return incorrect value for repeating events (thanks jjk) --- src/libs6/ftrigr_update.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libs6/ftrigr_update.c b/src/libs6/ftrigr_update.c index 68e3bde..132449b 100644 --- a/src/libs6/ftrigr_update.c +++ b/src/libs6/ftrigr_update.c @@ -1,7 +1,9 @@ /* ISC license. */ +#include #include #include +#include #include #include #include @@ -10,10 +12,19 @@ #include #include +static inline int appears (uint16_t, uint16_t const *, size_t) gccattr_pure ; + +static inline int appears (uint16_t id, uint16_t const *list, size_t len) +{ + while (len) if (id == list[--len]) return 1 ; + return 0 ; +} + static int msghandler (unixmessage_t const *m, void *context) { ftrigr_t *a = (ftrigr_t *)context ; ftrigr1_t *p ; + int addit = 1 ; uint16_t id ; if (m->len != 4 || m->nfds) return (errno = EPROTO, 0) ; uint16_unpack_big(m->s, &id) ; @@ -27,13 +38,21 @@ static int msghandler (unixmessage_t const *m, void *context) p->state = FR1STATE_WAITACK ; break ; case '!' : - if (p->options & FTRIGR_REPEAT) p->count++ ; + if (p->options & FTRIGR_REPEAT) + { + if (p->count++ + && appears(id+1, genalloc_s(uint16_t, &a->list), genalloc_len(uint16_t, &a->list))) + addit = 0 ; + } else p->state = FR1STATE_WAITACKDATA ; break ; default : return (errno = EPROTO, 0) ; } p->what = m->s[3] ; - id++ ; genalloc_append(uint16_t, &a->list, &id) ; + if (addit) + { + id++ ; genalloc_append(uint16_t, &a->list, &id) ; + } return 1 ; } -- cgit v1.2.3