issue-#191 Compiler trap by erroneous program

Post Reply
Zinn
Posts: 476
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main
Contact:

issue-#191 Compiler trap by erroneous program

Post by Zinn »

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.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: Compiler trap by erroneous program

Post by Josef Templ »

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
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

Re: issue-#191 Compiler trap by erroneous program

Post by luowy »

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
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#191 Compiler trap by erroneous program

Post by Josef Templ »

thanks, luowy, I will look into this tomorrow.

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

Re: issue-#191 Compiler trap by erroneous program

Post by Josef Templ »

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/p ... 4e641e5c4b


- Josef
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

Re: issue-#191 Compiler trap by erroneous program

Post by luowy »

the revised code works well, but the title is a bit fuzzy, how about "compiler trap by NEW procedure" ?
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#191 Compiler trap by erroneous program

Post by Josef Templ »

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: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#191 Compiler trap by erroneous program

Post by Josef Templ »

any suggestions about the title?

Otherwise this topic is also ready for voting.

- Josef
Post Reply