Browse Source

Fixed size detection in decimal integer scanning: overflow of a multiplication does not necessarily give a negative result. E.g. 1000000000 * 10 overflows with result 1 410 065 408. Now checking overflow before multiplication

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6448 8c9fc860-2736-0410-a75d-ab315db34111
eth.tmartiel 9 năm trước cách đây
mục cha
commit
a0a27bb316
1 tập tin đã thay đổi với 2 bổ sung0 xóa
  1. 2 0
      source/FoxScanner.Mod

+ 2 - 0
source/FoxScanner.Mod

@@ -695,6 +695,7 @@ TYPE
 						symbol.numberType := Integer;
 						WHILE (i < n) & ~long  DO
 							d := Decimal( dig[i] );  INC( i );
+							IF symbol.integer >= MAX(LONGINT) DIV 10 THEN (* multiplication overflow *)long := TRUE END;
 							nextInt := symbol.integer*10+d;
 							IF nextInt >=0 THEN symbol.integer := nextInt ELSE (* overflow *) long := TRUE END;
 						END;
@@ -705,6 +706,7 @@ TYPE
 							symbol.numberType := Hugeint;
 							WHILE i < n DO
 								d := Decimal( dig[i] );  INC( i );
+								IF hugeint >= MAX(HUGEINT) DIV 10 THEN Error( Basic.NumberTooLarge) END;
 								hugeint := hugeint * tenh + d;
 								IF hugeint < 0 THEN Error( Basic.NumberTooLarge ) END
 							END;