Explorar o código

* another fix for bug #39758, this time the end of the string

(cherry picked from commit 2df9dd9c146279cdf698dd1e35e467e686959b03)
marcoonthegit %!s(int64=3) %!d(string=hai) anos
pai
achega
47e90d7dda
Modificáronse 1 ficheiros con 2 adicións e 2 borrados
  1. 2 2
      rtl/objpas/sysutils/sysencoding.inc

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

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