nitj: avoid dead code execution
authorAlexandre Terrasa <alexandre@moz-code.org>
Mon, 13 Jul 2015 17:36:53 +0000 (13:36 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 21 Jul 2015 21:23:22 +0000 (17:23 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/compiler/java_compiler.nit

index 50c9bc5..8f8faa3 100644 (file)
@@ -634,6 +634,14 @@ class JavaCompilerVisitor
        # Compile a statement (if any)
        fun stmt(nexpr: nullable AExpr) do
                if nexpr == null then return
+               if nexpr.mtype == null and not nexpr.is_typed then
+                       # Untyped expression.
+                       # Might mean dead code or invalid code
+                       # so aborts
+                       add_abort("FATAL: bad statement executed.")
+                       return
+               end
+
                var old = self.current_node
                current_node = nexpr
                nexpr.stmt(self)
@@ -651,6 +659,19 @@ class JavaCompilerVisitor
                        res = nexpr.expr(self)
                end
 
+               if res == null then
+                       # Untyped expression.
+                       # Might mean dead code or invalid code.
+                       # so aborts
+                       add_abort("FATAL: bad expression executed.")
+                       # and return a placebo result to please the C compiler
+                       if mtype == null then mtype = compiler.mainmodule.object_type
+                       res = null_instance
+
+                       self.current_node = old
+                       return res
+               end
+
                if mtype != null then
                        mtype = anchor(mtype)
                        res = autobox(res, mtype)