Slint: fix bug when mopen/mclose is not in a function's body 95/17395/2
Calixte DENIZET [Tue, 27 Oct 2015 09:28:45 +0000 (10:28 +0100)]
Change-Id: Iee1d3985aa5a4000d3010c23fc36053f9e700444

scilab/modules/slint/src/cpp/MopenMcloseChecker.cpp

index b0e3959..c8eba5a 100644 (file)
@@ -36,7 +36,10 @@ void MopenMcloseChecker::preCheckNode(const ast::Exp & e, SLintContext & context
                     if (ae.getLeftExp().isSimpleVar())
                     {
                         const symbol::Symbol & Lsym = static_cast<const ast::SimpleVar &>(ae.getLeftExp()).getSymbol();
-                        fd.top().emplace(Lsym, ae.getLeftExp().getLocation());
+                        if (!fd.empty())
+                        {
+                            fd.top().emplace(Lsym, ae.getLeftExp().getLocation());
+                        }
                     }
                     else if (ae.getLeftExp().isArrayListExp())
                     {
@@ -47,7 +50,10 @@ void MopenMcloseChecker::preCheckNode(const ast::Exp & e, SLintContext & context
                             if (first.isSimpleVar())
                             {
                                 const symbol::Symbol & Lsym = static_cast<const ast::SimpleVar &>(first).getSymbol();
-                                fd.top().emplace(Lsym, first.getLocation());
+                                if (!fd.empty())
+                                {
+                                    fd.top().emplace(Lsym, first.getLocation());
+                                }
                             }
                         }
                     }
@@ -66,12 +72,18 @@ void MopenMcloseChecker::preCheckNode(const ast::Exp & e, SLintContext & context
                     if (first.isStringExp() && static_cast<const ast::StringExp &>(first).getValue() == L"all")
                     {
                         result.report(context, e.getLocation(), *this, _("The instruction mclose(\"all\") may have any side effets."));
-                        fd.top().clear();
+                        if (!fd.empty())
+                        {
+                            fd.top().clear();
+                        }
                     }
                     else if (first.isSimpleVar())
                     {
                         const symbol::Symbol & Lsym = static_cast<const ast::SimpleVar &>(first).getSymbol();
-                        fd.top().erase(Lsym);
+                        if (!fd.empty())
+                        {
+                            fd.top().erase(Lsym);
+                        }
                     }
                 }
             }