From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: [PATCH] evaluate.c: fix a gcc 'may be used uninitialized' warning
Date: Sun, 21 Jun 2020 20:34:31 +0100 [thread overview]
Message-ID: <b3ff0d78-ceea-768e-339c-22466b84b81d@ramsayjones.plus.com> (raw)
Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
Hi Luc,
Thanks for v0.6.2! :-D
However, I am seeing a gcc compiler warning:
CC evaluate.o
evaluate.c: In function ‘evaluate_generic_selection’:
evaluate.c:3310:38: warning: ‘base’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if (base->type == SYM_ARRAY && base->array_size) {
~~~~^~~~~~~~~~~~
This patch is just an FYI/quick-fix for this warning. The patch
I wanted to send, moved the declaration of the base symbol into
a new block at the 'if (stype->type == SYM_NODE)' conditional,
which would now include the (indented) SYM_ARRAY conditional
block. This, of course, meant that the SYM_ARRAY conditional was
indented too far to the right ... ;-)
[perhaps this argues for that code to be refactored into a function]
Thanks!
ATB,
Ramsay Jones
evaluate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/evaluate.c b/evaluate.c
index aa0f2080..19a15ca3 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -3299,7 +3299,7 @@ static struct symbol *evaluate_generic_selection(struct expression *expr)
source.ctype.modifiers &= ~(MOD_QUALIFIER|MOD_ATOMIC);
for (map = expr->map; map; map = map->next) {
struct symbol *stype = map->type;
- struct symbol *base;
+ struct symbol *base = NULL;
if (!evaluate_symbol(stype))
continue;
@@ -3307,7 +3307,7 @@ static struct symbol *evaluate_generic_selection(struct expression *expr)
if (stype->type == SYM_NODE)
base = stype->ctype.base_type;
- if (base->type == SYM_ARRAY && base->array_size) {
+ if (base && base->type == SYM_ARRAY && base->array_size) {
get_expression_value_silent(base->array_size);
if (base->array_size->type == EXPR_VALUE)
continue;
--
2.27.0
next reply other threads:[~2020-06-21 19:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-21 19:34 Ramsay Jones [this message]
2020-06-21 20:18 ` [PATCH] evaluate.c: fix a gcc 'may be used uninitialized' warning Luc Van Oostenryck
2020-06-21 20:18 ` Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b3ff0d78-ceea-768e-339c-22466b84b81d@ramsayjones.plus.com \
--to=ramsay@ramsayjones.plus.com \
--cc=linux-sparse@vger.kernel.org \
--cc=luc.vanoostenryck@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox