compiler: fix null-dereference on invalid len() arg.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 28 Mar 2012 22:31:02 +0000 (22:31 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 28 Mar 2012 22:31:02 +0000 (22:31 +0000)
This patch fixes an ICE caused by syntax errors in arguments
to unary built-in functions like len().

Updates issue 7.

From Rémy Oudompheng.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@185935 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/expressions.cc

index f1e0639..13c7de3 100644 (file)
@@ -6609,7 +6609,7 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
       if (this->code_ == BUILTIN_LEN || this->code_ == BUILTIN_CAP)
        {
          Expression* arg = this->one_arg();
-         if (!arg->is_constant())
+         if (arg != NULL && !arg->is_constant())
            {
              Find_call_expression find_call;
              Expression::traverse(&arg, &find_call);
@@ -6929,7 +6929,7 @@ Expression*
 Builtin_call_expression::one_arg() const
 {
   const Expression_list* args = this->args();
-  if (args->size() != 1)
+  if (args == NULL || args->size() != 1)
     return NULL;
   return args->front();
 }