瀏覽代碼

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 年之前
父節點
當前提交
a0a27bb316
共有 1 個文件被更改,包括 2 次插入0 次删除
  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;