浏览代码

* detect division by zero in tmoddiv.simplify (mantis #9499)

git-svn-id: trunk@8341 -
Jonas Maebe 18 年之前
父节点
当前提交
ac22ff09da
共有 4 个文件被更改,包括 28 次插入6 次删除
  1. 2 0
      .gitattributes
  2. 7 6
      compiler/nmat.pas
  3. 9 0
      tests/webtbf/tw9499.pp
  4. 10 0
      tests/webtbf/tw9499a.pp

+ 2 - 0
.gitattributes

@@ -7430,6 +7430,8 @@ tests/webtbf/tw9039b.pp svneol=native#text/plain
 tests/webtbf/tw9039c.pp svneol=native#text/plain
 tests/webtbf/tw9039d.pp svneol=native#text/plain
 tests/webtbf/tw9225.pp svneol=native#text/plain
+tests/webtbf/tw9499.pp svneol=native#text/plain
+tests/webtbf/tw9499a.pp svneol=native#text/plain
 tests/webtbf/uw0744.pp svneol=native#text/plain
 tests/webtbf/uw0840a.pp svneol=native#text/plain
 tests/webtbf/uw0840b.pp svneol=native#text/plain

+ 7 - 6
compiler/nmat.pas

@@ -120,6 +120,12 @@ implementation
                 end;
                 exit;
               end;
+            if tordconstnode(right).value = 0 then
+              begin
+                Message(parser_e_division_by_zero);
+                { recover }
+                tordconstnode(right).value := 1;
+              end;
           end;
 
         if is_constintnode(right) and is_constintnode(left) then
@@ -183,13 +189,8 @@ implementation
          { check for division by zero }
          if is_constintnode(right) then
            begin
+             { division by zero is already checked in simplify }
              rv:=tordconstnode(right).value;
-             if (rv=0) then
-               begin
-                 Message(parser_e_division_by_zero);
-                 { recover }
-                 rv:=1;
-               end;
             end;
 
          { if one operand is a cardinal and the other is a positive constant, convert the }

+ 9 - 0
tests/webtbf/tw9499.pp

@@ -0,0 +1,9 @@
+{ %fail }
+
+program Project1;
+
+var
+  i: Longint;
+begin
+  i := 2 div 0;
+end.

+ 10 - 0
tests/webtbf/tw9499a.pp

@@ -0,0 +1,10 @@
+{ %fail }
+
+program Project1;
+
+var
+  i: Longint;
+begin
+  i := 2;
+  i := i div 0;
+end.