Browse Source

* move char index checks up. fixes bug #39758

(cherry picked from commit 5b90eaf2dd3a153f2fdf7da85420eabe7432687b)
marcoonthegit 3 years ago
parent
commit
dbf1d63fff
1 changed files with 4 additions and 4 deletions
  1. 4 4
      rtl/objpas/sysutils/sysencoding.inc

+ 4 - 4
rtl/objpas/sysutils/sysencoding.inc

@@ -326,10 +326,10 @@ end;
 
 function TEncoding.GetByteCount(const S: UnicodeString; CharIndex, CharCount: Integer): Integer;
 begin
-  if (CharCount < 0) or (Length(S) < CharCount + CharIndex) then
-    raise EEncodingError.CreateFmt(SInvalidCount, [CharCount]);
   if (CharIndex < 1) then
     raise EEncodingError.CreateFmt(SCharacterIndexOutOfBounds, [CharIndex]);
+  if (CharCount < 0) or (Length(S) < CharCount + CharIndex) then
+    raise EEncodingError.CreateFmt(SInvalidCount, [CharCount]);
   Result := GetByteCount(@S[CharIndex], CharCount);
 end;
 
@@ -385,10 +385,10 @@ begin
     raise EEncodingError.Create(SInvalidDestinationArray);
   if (ByteIndex < 0) or (ByteLen < ByteIndex) then
     raise EEncodingError.CreateFmt(SInvalidDestinationIndex, [ByteIndex]);
-  if (CharCount < 0) or (Length(S) < CharCount + CharIndex) then
-    raise EEncodingError.CreateFmt(SInvalidCount, [CharCount]);
   if (CharIndex < 1) then
     raise EEncodingError.CreateFmt(SCharacterIndexOutOfBounds, [CharIndex]);
+  if (CharCount < 0) or (Length(S) < CharCount + CharIndex) then
+    raise EEncodingError.CreateFmt(SInvalidCount, [CharCount]);
   Result := GetBytes(@S[CharIndex], CharCount, @Bytes[ByteIndex], ByteLen - ByteIndex);
 end;