From: Todd C. Miller Date: Fri, 12 May 2017 15:56:06 +0000 (-0600) Subject: Add workaround for clang static analyzer being confused by LIST_REMOVE X-Git-Tag: SUDO_1_8_21^2~92 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2a83557e270debd72eb6dde5afce83b82684bd9;p=sudo Add workaround for clang static analyzer being confused by LIST_REMOVE and TAILQ_REMOVE. --- diff --git a/include/sudo_queue.h b/include/sudo_queue.h index 98010eecd..f48daf962 100644 --- a/include/sudo_queue.h +++ b/include/sudo_queue.h @@ -161,6 +161,19 @@ struct qm_trace { #endif /* QUEUE_MACRO_DEBUG */ /* + * XXX - Work around a bug in the llvm static analyzer. + * https://bugs.llvm.org//show_bug.cgi?id=18222 + */ +#ifdef __clang_analyzer__ +# define ANALYZER_ASSERT(x) do { \ + if (!__builtin_expect(!(x), 0)) \ + __builtin_trap(); \ +} while (0) +#else +# define ANALYZER_ASSERT(x) do {} while (0) +#endif /* __clang_analyzer__ */ + + /* * Singly-linked List declarations. */ #undef SLIST_HEAD @@ -505,6 +518,7 @@ struct { \ #undef LIST_REMOVE #define LIST_REMOVE(elm, field) do { \ + ANALYZER_ASSERT(elm != NULL); \ QMD_SAVELINK(oldnext, (elm)->field.le_next); \ QMD_SAVELINK(oldprev, (elm)->field.le_prev); \ if (LIST_NEXT((elm), field) != NULL) \ @@ -686,6 +700,7 @@ struct { \ #undef TAILQ_REMOVE #define TAILQ_REMOVE(head, elm, field) do { \ + ANALYZER_ASSERT(elm != NULL); \ QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \ QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \ if ((TAILQ_NEXT((elm), field)) != NULL) \