From b851e45e0a64c01ae77468aa7bc851715b31613b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 10 Mar 2017 19:42:31 +0000 Subject: Fix seg fault for global declarations declared erroneously without a name --- Source/CParse/parser.y | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'Source/CParse/parser.y') diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 1e8208ce8..69dce5534 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -3040,29 +3040,34 @@ c_decl : storage_class type declarator initializer c_decl_tail { Setattr($$,"bitfield", $4.bitfield); } - /* Look for "::" declarations (ignored) */ - if (Strstr($3.id,"::")) { - /* This is a special case. If the scope name of the declaration exactly - matches that of the declaration, then we will allow it. Otherwise, delete. */ - String *p = Swig_scopename_prefix($3.id); - if (p) { - if ((Namespaceprefix && Strcmp(p, Namespaceprefix) == 0) || - (Classprefix && Strcmp(p, Classprefix) == 0)) { - String *lstr = Swig_scopename_last($3.id); - Setattr($$,"name",lstr); - Delete(lstr); - set_nextSibling($$,$5); + if ($3.id) { + /* Look for "::" declarations (ignored) */ + if (Strstr($3.id, "::")) { + /* This is a special case. If the scope name of the declaration exactly + matches that of the declaration, then we will allow it. Otherwise, delete. */ + String *p = Swig_scopename_prefix($3.id); + if (p) { + if ((Namespaceprefix && Strcmp(p, Namespaceprefix) == 0) || + (Classprefix && Strcmp(p, Classprefix) == 0)) { + String *lstr = Swig_scopename_last($3.id); + Setattr($$, "name", lstr); + Delete(lstr); + set_nextSibling($$, $5); + } else { + Delete($$); + $$ = $5; + } + Delete(p); } else { Delete($$); $$ = $5; } - Delete(p); } else { - Delete($$); - $$ = $5; + set_nextSibling($$, $5); } } else { - set_nextSibling($$,$5); + Swig_error(cparse_file, cparse_line, "Missing symbol name for global declaration\n"); + $$ = 0; } } /* Alternate function syntax introduced in C++11: -- cgit v1.2.3