Browse Source

* Merging revisions 45223 from trunk:
------------------------------------------------------------------------
r45223 | michael | 2020-05-02 17:56:30 +0200 (Sat, 02 May 2020) | 1 line

* Explicitly raise EDivError (bug ID 36839)
------------------------------------------------------------------------

git-svn-id: branches/fixes_3_2@45224 -

michael 5 years ago
parent
commit
76effcf10d
1 changed files with 19 additions and 4 deletions
  1. 19 4
      packages/fcl-base/src/fpexprpars.pp

+ 19 - 4
packages/fcl-base/src/fpexprpars.pp

@@ -896,6 +896,7 @@ Resourcestring
   SErrCaseLabelNotAConst = 'Case label %d "%s" is not a constant expression';
   SErrCaseLabelNotAConst = 'Case label %d "%s" is not a constant expression';
   SErrCaseLabelType = 'Case label %d "%s" needs type %s, but has type %s';
   SErrCaseLabelType = 'Case label %d "%s" needs type %s, but has type %s';
   SErrCaseValueType = 'Case value %d "%s" needs type %s, but has type %s';
   SErrCaseValueType = 'Case value %d "%s" needs type %s, but has type %s';
+  SErrDivisionByZero = '%d division by zero';
 
 
 { ---------------------------------------------------------------------
 { ---------------------------------------------------------------------
   Auxiliary functions
   Auxiliary functions
@@ -3564,13 +3565,27 @@ begin
   Left.GetNodeValue(Result);
   Left.GetNodeValue(Result);
   Right.GetNodeValue(RRes);
   Right.GetNodeValue(RRes);
   case Result.ResultType of
   case Result.ResultType of
-    rtInteger  : Result.ResFloat:=Result.ResInteger/RRes.ResInteger;
-    rtFloat    : Result.ResFloat:=Result.ResFloat/RRes.ResFloat;
+    rtInteger  :
+      if RRes.ResInteger<>0 then
+        Result.ResFloat:=Result.ResInteger/RRes.ResInteger
+      else
+        RaiseParserError(SErrDivisionByZero, [ResultTypeName(rtInteger)]);
+    rtFloat    :
+      if RRes.ResFloat<>0 then
+        Result.ResFloat:=Result.ResFloat/RRes.ResFloat
+      else
+        RaiseParserError(SErrDivisionByZero, [ResultTypeName(rtInteger)]);
     rtCurrency :
     rtCurrency :
         if NodeType=rtCurrency then
         if NodeType=rtCurrency then
-          Result.ResCurrency:=Result.ResCurrency/RRes.ResCurrency
+           if RRes.ResCurrency <> 0 then
+             Result.ResCurrency:=Result.ResCurrency/RRes.ResCurrency
+           else
+             RaiseParserError(SErrDivisionByZero, [ResultTypeName(rtCurrency)])
         else
         else
-          Result.ResFloat:=Result.ResFloat/RRes.ResFloat;
+          if RRes.ResFloat<> 0 then
+            Result.ResFloat:=Result.ResFloat/RRes.ResFloat
+          else
+            RaiseParserError(SErrDivisionByZero, [ResultTypeName(rtFloat)]);
   end;
   end;
   Result.ResultType:=NodeType;
   Result.ResultType:=NodeType;
 end;
 end;