From 47e90d7ddaf0faebccd83b6a6c3872b0daf4e42a Mon Sep 17 00:00:00 2001 From: marcoonthegit Date: Sun, 5 Jun 2022 17:46:58 +0200 Subject: [PATCH] * another fix for bug #39758, this time the end of the string (cherry picked from commit 2df9dd9c146279cdf698dd1e35e467e686959b03) --- rtl/objpas/sysutils/sysencoding.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rtl/objpas/sysutils/sysencoding.inc b/rtl/objpas/sysutils/sysencoding.inc index a5051a425c..1d82cde49f 100644 --- a/rtl/objpas/sysutils/sysencoding.inc +++ b/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;