issue-#191 Compiler trap by erroneous program

issue-#191 Compiler trap by erroneous program

Postby Zinn » Thu Nov 08, 2018 3:18 pm

The compiler produce a NIL dereference (read) trap instead of an error message

Code: Select all
MODULE TestCompilerError;

   CONST
      length = 5;

   PROCEDURE Name* (): POINTER TO ARRAY OF CHAR;
      VAR string: POINTER TO ARRAY OF CHAR;
   BEGIN
      NEW(string, LEN length + 1);
      RETURN string
   END Name;

END TestCompilerError.

Reported by Rainer Neubauer.
Last edited by Zinn on Fri Nov 09, 2018 7:48 am, edited 2 times in total.
Zinn
 
Posts: 455
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main

Re: Compiler trap by erroneous program

Postby Josef Templ » Fri Nov 09, 2018 7:37 am

I can confirm the bug and I have added an issue for this.
see https://redmine.blackboxframework.org/issues/191.

Helmut, can you rename this topic to the usual form with the issue-#191 prepended?

- Josef
User avatar
Josef Templ
 
Posts: 1909
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#191 Compiler trap by erroneous program

Postby luowy » Sat Nov 10, 2018 2:19 am

The easiest way is guard the "node" not NIL, I didn't find out what side effects it has.
DevCPB.StParN
Code: Select all
                 ....
         ELSIF f IN intSet THEN
            IF f = Int64 THEN Convert(x, DevCPT.int32typ) END;
            IF (x.class = Nconst) & (x.conval.intval <= 0) THEN err(63) END;
            node := p.right;
            IF node # NIL THEN   (*+++*)
               WHILE node.link # NIL DO node := node.link END;
               node.link := x; p.typ := p.typ.BaseTyp
            END   (* +++ *)
         ELSE err(111)
         END
                ....

luowy
luowy
 
Posts: 183
Joined: Mon Oct 20, 2014 12:52 pm

Re: issue-#191 Compiler trap by erroneous program

Postby Josef Templ » Sat Nov 10, 2018 11:48 am

thanks, luowy, I will look into this tomorrow.

- Josef
User avatar
Josef Templ
 
Posts: 1909
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#191 Compiler trap by erroneous program

Postby Josef Templ » Sun Nov 11, 2018 11:56 am

I have fixed the trap as proposed by luowy.
In addition, I have added trivial error recovery code:
instead of appending to a non-empty list in the error case, the first element is inserted into the list.
The error message has been generated before.

For the changes see https://redmine.blackboxframework.org/projects/blackbox/repository/diff?utf8=%E2%9C%93&rev=a52a74d8cec9f3fd62950638258aed012de051be&rev_to=a940ecb3063c8387b57c69e4496ea14e641e5c4b


- Josef
User avatar
Josef Templ
 
Posts: 1909
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#191 Compiler trap by erroneous program

Postby luowy » Mon Nov 12, 2018 2:36 pm

the revised code works well, but the title is a bit fuzzy, how about "compiler trap by NEW procedure" ?
luowy
 
Posts: 183
Joined: Mon Oct 20, 2014 12:52 pm

Re: issue-#191 Compiler trap by erroneous program

Postby Josef Templ » Mon Nov 12, 2018 9:10 pm

luowy wrote:the revised code works well, but the title is a bit fuzzy, how about "compiler trap by NEW procedure" ?


I agree that the title could be improved.
However, it should also not remove the fact that the trap is only a follow-up error after another error.
This is hard to express in only a few words.

The precise title would be something like this:
"Compiler trap after invalid first dimension of dynamic array NEW"

- Josef
User avatar
Josef Templ
 
Posts: 1909
Joined: Tue Sep 17, 2013 6:50 am


Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest

cron