mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 06:09:11 +02:00
* proper range checking for TryStrToDWord, should resolve all issues in #39406
(cherry picked from commit 983fbff871
)
This commit is contained in:
parent
bbffe9e26a
commit
d1166342ca
@ -1006,10 +1006,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TryStrToDWord(const s: string; Out D: DWord): boolean;
|
function TryStrToDWord(const s: string; Out D: DWord): boolean;
|
||||||
var Error : word;
|
var
|
||||||
|
Error : word;
|
||||||
|
lq : QWord;
|
||||||
begin
|
begin
|
||||||
Val(s, D, Error);
|
Val(s, lq, Error);
|
||||||
TryStrToDWord:=Error=0
|
TryStrToDWord:=(Error=0) and (lq<=High(DWord));
|
||||||
|
if TryStrToDWord then
|
||||||
|
D:=lq;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function StrToUInt(const s: string): Cardinal;
|
function StrToUInt(const s: string): Cardinal;
|
||||||
|
14
tests/webtbs/tw39406.pp
Normal file
14
tests/webtbs/tw39406.pp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{$mode objfpc}
|
||||||
|
program fpbug;
|
||||||
|
|
||||||
|
uses
|
||||||
|
SysUtils;
|
||||||
|
|
||||||
|
var
|
||||||
|
Value: Cardinal;
|
||||||
|
Success: Boolean;
|
||||||
|
begin
|
||||||
|
Success := TryStrToDword('7795000000', Value);
|
||||||
|
if Success then
|
||||||
|
halt(1);
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user