Check bounds in SetLength(shortstring).

This commit is contained in:
Rika Ichinose 2024-04-10 21:06:14 +03:00
parent dc7130d078
commit fc3d71bba3

View File

@ -19,8 +19,10 @@
{$define FPC_HAS_SHORTSTR_SETLENGTH} {$define FPC_HAS_SHORTSTR_SETLENGTH}
procedure fpc_Shortstr_SetLength(var s:shortstring;len:SizeInt);[Public,Alias : 'FPC_SHORTSTR_SETLENGTH']; compilerproc; procedure fpc_Shortstr_SetLength(var s:shortstring;len:SizeInt);[Public,Alias : 'FPC_SHORTSTR_SETLENGTH']; compilerproc;
begin begin
if Len>255 then if len<0 then
Len:=255; len:=0;
if len>high(s) then
len:=high(s);
s[0]:=chr(len); s[0]:=chr(len);
end; end;
{$endif FPC_HAS_SHORTSTR_SETLENGTH} {$endif FPC_HAS_SHORTSTR_SETLENGTH}