[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] warnings: address -Wnull-dereference in reader.c
From: |
Akim Demaille |
Subject: |
Re: [PATCH] warnings: address -Wnull-dereference in reader.c |
Date: |
Sun, 5 Aug 2018 16:40:01 +0200 |
> Le 8 juil. 2018 à 20:08, David Michael <address@hidden> a écrit :
>
> This corrects a build failure when using GCC8 and configured with
> the --enable-gcc-warnings and --enable-assert options:
hi David, thanks!
I will install this slightly different version of your patch:
commit bda804d42aaf03c11869cfb1e0818d416d27b22c
Author: Akim Demaille <address@hidden>
Date: Sun Aug 5 16:29:00 2018 +0200
warnings: address -Wnull-dereference in reader.c
Based on a patch by David Michael.
http://lists.gnu.org/archive/html/bison-patches/2018-07/msg00000.html
* src/reader.c (find_start): New, extracted from...
(check_and_convert_grammar): here.
diff --git a/THANKS b/THANKS
index 74f04dd4..9d37dc84 100644
--- a/THANKS
+++ b/THANKS
@@ -39,6 +39,7 @@ Daniel Galloway address@hidden
Daniel Hagerty address@hidden
David J. MacKenzie address@hidden
David Kastrup address@hidden
+David Michael address@hidden
Dennis Clarke address@hidden
Derek Clegg address@hidden
Derek M. Jones address@hidden
diff --git a/src/reader.c b/src/reader.c
index 975f7c8d..153326d6 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -723,6 +723,25 @@ prepare_percent_define_front_end_variables (void)
}
}
+/* Find the first LHS which is not a dummy. */
+static symbol *
+find_start ()
+{
+ symbol_list *res = grammar;
+ for (;
+ res != NULL && symbol_is_dummy (res->content.sym);
+ res = res->next)
+ {
+ for (res = res->next;
+ res != NULL && res->content.sym != NULL;
+ res = res->next)
+ continue;
+ aver (res != NULL);
+ }
+ aver (res != NULL);
+ return res->content.sym;
+}
+
/*-------------------------------------------------------------.
| Check the grammar that has just been read, and convert it to |
@@ -749,22 +768,12 @@ check_and_convert_grammar (void)
/* Report any undefined symbols and consider them nonterminals. */
symbols_check_defined ();
- /* Find the start symbol if no %start. */
+ /* Find the start symbol if no %start: the first LHS which is not a
+ dummy. */
if (!start_flag)
{
- symbol_list *node;
- for (node = grammar;
- node != NULL && symbol_is_dummy (node->content.sym);
- node = node->next)
- {
- for (node = node->next;
- node != NULL && node->content.sym != NULL;
- node = node->next)
- continue;
- }
- aver (node != NULL);
- grammar_start_symbol_set (node->content.sym,
- node->content.sym->location);
+ symbol *start = find_start ();
+ grammar_start_symbol_set (start, start->location);
}
/* Insert the initial rule, whose line is that of the first rule
- Re: [PATCH] warnings: address -Wnull-dereference in reader.c,
Akim Demaille <=