CHAR range-checking breach

Post Reply
User avatar
adimetrius
Posts: 68
Joined: Sun Aug 04, 2019 1:02 pm

CHAR range-checking breach

Post by adimetrius »

When range-checking is enabled, the following should produce a run-time trap 'index out of range' at (*X*) and (*XX*), but it doesn't; instead, it produces a TRAP 0, displaying that i = 65536, r = 65536.0, c = 0X, d = 0X at (*XXX*).

Code: Select all

MODULE M;
	PROCEDURE P*;
		VAR c, d: CHAR; i: INTEGER;
	BEGIN i := 65536; r := 65536;
		c := CHR(i)			 (*X*); 
		d := CHR(ENTIER(r));		 (*XX*);
		HALT(0)				 (*XXX*)
	END P;
END M.
(!)DevCompiler.CompileThis M+ (!) mind the plus - it enables range-checking.
I think it is a small omission in PROCEDURE DevCPC486.ConvMove. 65536 should be replaced with an obvious 65535 in the lines

Code: Select all

	ELSIF f = Char16 THEN Check(y, 0, 65536)
to fix CHR(INTEGER) range checking and

Code: Select all

	ELSIF f = Char16 THEN Check(y, 0, 65536); FreeHi(y)
to fix CHR(ENTIER(REAL)) range checking.

I move to make this amendment.
luowy
Posts: 87
Joined: Thu Dec 17, 2015 1:32 pm

Re: CHAR range-checking breach

Post by luowy »

agree, 65536 is incorrect, should be fixed. not sure add FreeHi(y) or not.
Post Reply