mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-07 03:58:47 +02:00
* Fix integer overflow not being detected. Issue #39406
This commit is contained in:
parent
ee10850a57
commit
1e74c418ae
@ -960,10 +960,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TryStrToInt(const s: string; out i : Longint) : boolean;
|
function TryStrToInt(const s: string; out i : Longint) : boolean;
|
||||||
var Error : word;
|
var
|
||||||
|
Error : word;
|
||||||
|
li : Int64;
|
||||||
begin
|
begin
|
||||||
Val(s, i, Error);
|
Val(s, li, Error);
|
||||||
TryStrToInt:=Error=0
|
TryStrToInt:=(Error=0) and (li<=High(Longint)) and (li>=Low(Longint));
|
||||||
|
if TryStrToInt then
|
||||||
|
i:=li;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ StrToInt converts the string S to an integer value,
|
{ StrToInt converts the string S to an integer value,
|
||||||
|
Loading…
Reference in New Issue
Block a user