diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-01-31 13:09:30 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-02-01 17:52:18 +0100 |
| commit | 58346b848ce3febccbfb2e2db7ad4262f0630a97 (patch) | |
| tree | 3b4129caf3832028fcc450a6a03eb111ca12a81b /evaluate.c | |
| parent | 0687a6f961540a472161b183cc927262454d2186 (diff) | |
| download | sparse-dev-58346b848ce3febccbfb2e2db7ad4262f0630a97.tar.gz | |
early return if null ctype in evaluate_conditional()
This function contains a few tests which must only be done
if the type is valid, same for the final call to degenerate().
Currently this is done by an "if (ctype) { ... }" but this
cause multiple NULL tests, take screen real estate and is
somehow error prone.
Change this by returning as soon as we know the ctype is
invalid since nothing good can be done after it.
This also makes, IMO, the code clearer.
NB: no functional changes here.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'evaluate.c')
| -rw-r--r-- | evaluate.c | 32 |
1 files changed, 15 insertions, 17 deletions
@@ -879,25 +879,23 @@ static struct symbol *evaluate_conditional(struct expression *expr, int iterator warning(expr->pos, "assignment expression in conditional"); ctype = evaluate_expression(expr); - if (ctype) { - if (is_safe_type(ctype)) - warning(expr->pos, "testing a 'safe expression'"); - if (is_func_type(ctype)) { - if (Waddress) - warning(expr->pos, "the address of %s will always evaluate as true", "a function"); - } else if (is_array_type(ctype)) { - if (Waddress) - warning(expr->pos, "the address of %s will always evaluate as true", "an array"); - } else if (!is_scalar_type(ctype)) { - sparse_error(expr->pos, "incorrect type in conditional"); - info(expr->pos, " got %s", show_typename(ctype)); - ctype = NULL; - } + if (!ctype) + return NULL; + if (is_safe_type(ctype)) + warning(expr->pos, "testing a 'safe expression'"); + if (is_func_type(ctype)) { + if (Waddress) + warning(expr->pos, "the address of %s will always evaluate as true", "a function"); + } else if (is_array_type(ctype)) { + if (Waddress) + warning(expr->pos, "the address of %s will always evaluate as true", "an array"); + } else if (!is_scalar_type(ctype)) { + sparse_error(expr->pos, "incorrect type in conditional"); + info(expr->pos, " got %s", show_typename(ctype)); + return NULL; } - if (ctype) - ctype = degenerate(expr); - + ctype = degenerate(expr); return ctype; } |
