From 55f010324835946394d88b02b5aa87755444b66e Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 15 Jan 2022 22:18:38 +0100 Subject: [PATCH] o patch by Bart B: * fixes fpc_Val_UInt_Shortstr, part of #15633 * fpc_val_qword_shortstr uses the ValueArray constant --- rtl/inc/sstrings.inc | 58 ++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/rtl/inc/sstrings.inc b/rtl/inc/sstrings.inc index 5deacbaeb5..e27816ccb9 100644 --- a/rtl/inc/sstrings.inc +++ b/rtl/inc/sstrings.inc @@ -1254,32 +1254,48 @@ Function fpc_Val_UInt_Shortstr({$ifndef VER3_2}DestSize: SizeInt;{$endif VER3_2} var base,u : byte; negative : boolean; + UpperLimit: ValUInt; +const + ValueArray : array['0'..'f'] of byte = (0,1,2,3,4,5,6,7,8,9,$FF,$FF,$FF,$FF,$FF,$FF,$FF,10,11,12,13,14,15, + $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF, + 10,11,12,13,14,15); begin fpc_Val_UInt_Shortstr:=0; Code:=InitVal(s,negative,base); If Negative or (Code>length(s)) Then - begin - if Negative then Code:=Pos('-',S); - Exit; - end; + begin + if Negative then Code:=Pos('-',S); + Exit; + end; if (s[Code]=#0) then begin if (Code>1) and (s[Code-1]='0') then Code:=0; exit; end; + {$ifndef VER3_2} + case DestSize of + 1: UpperLimit:=High(Byte); + 2: UpperLimit:=High(Word); + 4: UpperLimit:=High(DWord); + {$ifdef CPU64} + 8: UpperLimit:=High(QWord); + {$endif CPU64} + end; + {$else VER3_2} + UpperLimit:=High(ValUInt); //this preserves 3.2 (and earlier) behaviour + {$ENDIF} while Code<=Length(s) do begin - case s[Code] of - '0'..'9' : u:=Ord(S[Code])-Ord('0'); - 'A'..'F' : u:=Ord(S[Code])-(Ord('A')-10); - 'a'..'f' : u:=Ord(S[Code])-(Ord('a')-10); + u:=16; + case s[code] of + '0'..'f' : u:=ValueArray[S[Code]]; #0 : break; else - u:=16; + ; end; If (u>=base) or - (ValUInt(MaxUIntValue-u) div ValUInt(Base)=base) or ((QWord(maxqword-u) div QWord(base))