A static analysis tool reports that some callers of symbol_list_n_get
might get NULL and not handle it properly. This is not the case, yet
we can suppress this pattern.
Reported by Mike Sullivan.
<https://lists.gnu.org/archive/html/bug-bison/2013-12/msg00027.html>
* src/symlist.c (symbol_list_n_get): Actually it is never called
to return 0. Enforce this postcondition via aver.
(symbol_list_n_type_name_get): Simplify accordingly. In particular,
discards a (translated) useless error message.
* src/symlist.h: Adjust documentation.
* src/scan-code.l: Style change.
Michiel De Wilde mdewilde.agilent@gmail.com
Mickael Labau labau_m@epita.fr
Mike Castle dalgoda@ix.netcom.com
Michiel De Wilde mdewilde.agilent@gmail.com
Mickael Labau labau_m@epita.fr
Mike Castle dalgoda@ix.netcom.com
+Mike Sullivan Mike.sullivan@Oracle.COM
Neil Booth NeilB@earthling.net
Nelson H. F. Beebe beebe@math.utah.edu
Nick Bowler nbowler@elliptictech.com
Neil Booth NeilB@earthling.net
Nelson H. F. Beebe beebe@math.utah.edu
Nick Bowler nbowler@elliptictech.com
src/scan-code.l
src/scan-gram.l
src/scan-skel.l
src/scan-code.l
src/scan-gram.l
src/scan-skel.l
src/symtab.c
djgpp/subpipe.c
src/symtab.c
djgpp/subpipe.c
"]b4_rhs_value(%d, %d, ", effective_rule_length, n);
obstack_quote (&obstack_for_string, type_name);
obstack_sgrow (&obstack_for_string, ")[");
"]b4_rhs_value(%d, %d, ", effective_rule_length, n);
obstack_quote (&obstack_for_string, type_name);
obstack_sgrow (&obstack_for_string, ")[");
symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
true;
break;
symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
true;
break;
#include <config.h>
#include "system.h"
#include <config.h>
#include "system.h"
#include "symlist.h"
/*--------------------------------------.
#include "symlist.h"
/*--------------------------------------.
symbol_list_n_get (symbol_list *l, int n)
{
int i;
symbol_list_n_get (symbol_list *l, int n)
{
int i;
-
- if (n < 0)
- return NULL;
-
for (i = 0; i < n; ++i)
{
l = l->next;
for (i = 0; i < n; ++i)
{
l = l->next;
- if (l == NULL
- || (l->content_type == SYMLIST_SYMBOL && l->content.sym == NULL))
- return NULL;
+ aver (l->content_type == SYMLIST_SYMBOL);
+ aver (l->content.sym);
/*--------------------------------------------------------------.
| Get the data type (alternative in the union) of the value for |
| symbol N in symbol list L. |
/*--------------------------------------------------------------.
| Get the data type (alternative in the union) of the value for |
| symbol N in symbol list L. |
uniqstr
symbol_list_n_type_name_get (symbol_list *l, location loc, int n)
{
uniqstr
symbol_list_n_type_name_get (symbol_list *l, location loc, int n)
{
- l = symbol_list_n_get (l, n);
- if (!l)
- {
- complain (&loc, complaint, _("invalid $ value: $%d"), n);
- return NULL;
- }
- aver (l->content_type == SYMLIST_SYMBOL);
- return l->content.sym->type_name;
+ return symbol_list_n_get (l, n)->content.sym->type_name;
}
bool
symbol_list_null (symbol_list *node)
{
}
bool
symbol_list_null (symbol_list *node)
{
- return !node ||
- (node->content_type == SYMLIST_SYMBOL && !(node->content.sym));
+ return (!node
+ || (node->content_type == SYMLIST_SYMBOL && !node->content.sym));
/** Return the length of \c l. */
int symbol_list_length (symbol_list const *l);
/** Return the length of \c l. */
int symbol_list_length (symbol_list const *l);
-/** Get item \c n in symbol list \c l. */
+/** Get item \c n in symbol list \c l.
+ ** \pre 0 <= n
+ ** \post res != NULL
+ **/
symbol_list *symbol_list_n_get (symbol_list *l, int n);
/* Get the data type (alternative in the union) of the value for
symbol_list *symbol_list_n_get (symbol_list *l, int n);
/* Get the data type (alternative in the union) of the value for