kernel/queue: Fix SLIST_REMOVE macro This patch adds a missing NULL check of list element. Without that patch, if somebody wants to remove element which is not on the list, crash occurs
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/82c6878e Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/82c6878e Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/82c6878e Branch: refs/heads/develop Commit: 82c6878e75b257f4a1735c2ab68de72e2dc983c8 Parents: e9ff7ac Author: Åukasz Rymanowski <[email protected]> Authored: Sun Jan 29 23:44:17 2017 +0100 Committer: Åukasz Rymanowski <[email protected]> Committed: Thu Feb 2 12:59:59 2017 +0100 ---------------------------------------------------------------------- kernel/os/include/os/queue.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/82c6878e/kernel/os/include/os/queue.h ---------------------------------------------------------------------- diff --git a/kernel/os/include/os/queue.h b/kernel/os/include/os/queue.h index faffd85..a3a0790 100755 --- a/kernel/os/include/os/queue.h +++ b/kernel/os/include/os/queue.h @@ -158,10 +158,11 @@ struct { \ } \ else { \ struct type *curelm = SLIST_FIRST((head)); \ - while (SLIST_NEXT(curelm, field) != (elm)) \ - curelm = SLIST_NEXT(curelm, field); \ - SLIST_NEXT(curelm, field) = \ - SLIST_NEXT(SLIST_NEXT(curelm, field), field); \ + while (SLIST_NEXT(curelm, field) && \ + SLIST_NEXT(curelm, field) != (elm)) { \ + curelm = SLIST_NEXT(curelm, field); \ + } \ + SLIST_NEXT(curelm, field) = SLIST_NEXT(elm, field); \ } \ } while (0)
