* [PATCH] evaluate.c: fix a gcc 'may be used uninitialized' warning
@ 2020-06-21 19:34 Ramsay Jones
2020-06-21 20:18 ` Luc Van Oostenryck
0 siblings, 1 reply; 3+ messages in thread
From: Ramsay Jones @ 2020-06-21 19:34 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Sparse Mailing-list
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] evaluate.c: fix a gcc 'may be used uninitialized' warning
2020-06-21 19:34 [PATCH] evaluate.c: fix a gcc 'may be used uninitialized' warning Ramsay Jones
@ 2020-06-21 20:18 ` Luc Van Oostenryck
2020-06-21 20:18 ` Luc Van Oostenryck
0 siblings, 1 reply; 3+ messages in thread
From: Luc Van Oostenryck @ 2020-06-21 20:18 UTC (permalink / raw)
To: Ramsay Jones; +Cc: Sparse Mailing-list
On Sun, Jun 21, 2020 at 08:34:31PM +0100, Ramsay Jones wrote:
>
> 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]
I just saw this warning too. Of course, *after* the release is made.
What I had in made while writing the code was:
base = stype;
if (stype->type == SYM_NODE)
base = stype->ctype.base_type;
Your patch here below will work correctly but is not semantically
correct if stype->type != SYM_NODE. Fortunately, it's guaranteed
to always be a SYM_NODE (typename() is so). So, I'll probably
commit the following:
- if (stype->type == SYM_NODE)
- base = stype->ctype.base_type;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] evaluate.c: fix a gcc 'may be used uninitialized' warning
2020-06-21 20:18 ` Luc Van Oostenryck
@ 2020-06-21 20:18 ` Luc Van Oostenryck
0 siblings, 0 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2020-06-21 20:18 UTC (permalink / raw)
To: Ramsay Jones; +Cc: Sparse Mailing-list
On Sun, Jun 21, 2020 at 08:34:31PM +0100, Ramsay Jones wrote:
>
> 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]
I just saw this warning too. Of course, *after* the release is made.
What I had in made while writing the code was:
base = stype;
if (stype->type == SYM_NODE)
base = stype->ctype.base_type;
Your patch here below will work correctly but is not semantically
correct if stype->type != SYM_NODE. Fortunately, it's guaranteed
to always be a SYM_NODE (typename() is so). So, I'll probably
commit the following:
- if (stype->type == SYM_NODE)
- base = stype->ctype.base_type;
-
+ base = stype->ctype.base_type;
Thanks for the bug report and for giving a try to the release.
-- Luc
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-21 20:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-21 19:34 [PATCH] evaluate.c: fix a gcc 'may be used uninitialized' warning Ramsay Jones
2020-06-21 20:18 ` Luc Van Oostenryck
2020-06-21 20:18 ` Luc Van Oostenryck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).