From f1eccca3a6a37d234b1cf6b3955310a48dd14fa2 Mon Sep 17 00:00:00 2001
From: florian <florian@freepascal.org>
Date: Thu, 30 Jan 2020 21:23:10 +0000
Subject: [PATCH]   * catch exceptions in all variants of TextToFloat properly 
  * force x87 exceptions to be thrown on all platforms using x87

git-svn-id: trunk@44070 -
---
 rtl/objpas/sysutils/sysstr.inc | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/rtl/objpas/sysutils/sysstr.inc b/rtl/objpas/sysutils/sysstr.inc
index f78bb9b334..529ac2a77c 100644
--- a/rtl/objpas/sysutils/sysstr.inc
+++ b/rtl/objpas/sysutils/sysstr.inc
@@ -1213,7 +1213,18 @@ Begin
   P:=Pos(FormatSettings.DecimalSeparator,S);
   If (P<>0) Then
     S[P] := '.';
-  Val(trim(S),Value,E);
+  try
+    Val(trim(S),Value,E);
+  { on x87, a floating point exception may be pending in case of an invalid
+    input value -> trigger it now }
+{$if defined(cpui386) or (defined(cpux86_64) and not(defined(win64))) or defined(cpui8086)}
+    asm
+      fwait
+    end;
+{$endif}
+  except
+    E:=1;
+  end;
   Result:=(E=0);
 End;
 
@@ -1273,7 +1284,7 @@ Begin
     end;
   { on x87, a floating point exception may be pending in case of an invalid
     input value -> trigger it now }
-{$ifdef cpux86}
+{$if defined(cpui386) or (defined(cpux86_64) and not(defined(win64))) or defined(cpui8086)}
     asm
       fwait
     end;