From: Alan T. DeKok Date: Thu, 14 Jul 2022 23:58:39 +0000 (-0400) Subject: hoist static analysis checks to before when they're used X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c3ab6e7c452bf9da449ecdd081a788f84c678c8;p=thirdparty%2Ffreeradius-server.git hoist static analysis checks to before when they're used --- diff --git a/src/lib/util/dict_unknown.c b/src/lib/util/dict_unknown.c index 540fb1a528a..6756802a631 100644 --- a/src/lib/util/dict_unknown.c +++ b/src/lib/util/dict_unknown.c @@ -46,6 +46,10 @@ fr_dict_attr_t const *fr_dict_unknown_add(fr_dict_t *dict, fr_dict_attr_t const return NULL; } +#ifdef STATIC_ANALYZER + if (!unknown->name || !unknown->parent) return NULL; +#endif + da = fr_dict_attr_by_name(NULL, unknown->parent, unknown->name); if (da) { if (da->attr == unknown->attr) return da; @@ -65,9 +69,6 @@ fr_dict_attr_t const *fr_dict_unknown_add(fr_dict_t *dict, fr_dict_attr_t const return NULL; } } else { -#ifdef STATIC_ANALYZER - if (!unknown->parent) return NULL; -#endif parent = unknown->parent; } @@ -124,10 +125,6 @@ fr_dict_attr_t const *fr_dict_unknown_add(fr_dict_t *dict, fr_dict_attr_t const return n; } -#ifdef STATIC_ANALYZER - if (!unknown->name) return NULL; -#endif - /* * Add the attribute by both name and number. * diff --git a/src/lib/util/machine.c b/src/lib/util/machine.c index 72d4a0b98ca..e939d752825 100644 --- a/src/lib/util/machine.c +++ b/src/lib/util/machine.c @@ -216,6 +216,13 @@ fr_machine_t *fr_machine_alloc(TALLOC_CTX *ctx, fr_machine_def_t const *def, voi */ m->current = &m->state[def->init]; +#ifdef STATIC_ANALYZER + if (!m->current || !m->current->def || !m->current->def->process) { + talloc_free(m); + return NULL; + } +#endif + /* * We don't transition into the "init" state, as there is * no previous state. We just run the "process" @@ -234,13 +241,6 @@ fr_machine_t *fr_machine_alloc(TALLOC_CTX *ctx, fr_machine_def_t const *def, voi fr_assert(!m->current->def->exit); fr_assert(m->current->def->process); -#ifdef STATIC_ANALYZER - if (!m->current || !m->current->def || !m->current->def->process) { - talloc_free(m); - return NULL; - } -#endif - next = m->current->def->process(m, uctx); fr_assert(next >= 0);