Skip to content

Commit 266a13e

Browse files
Changed BytesToRawString
`BytesToRawString()` does not work correctly on macOS. For arbitary binary content, the function `StringOf()` will fail since it cannot form an Unicode string (I am not sure why it works for Windows). This implementation of BytesToRawString() will work for both Windows and macOS.
1 parent 7d2ade9 commit 266a13e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Source/DECUtil.pas

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,6 @@ procedure ProtectString(var Source: WideString); overload;
216216
/// RawByteString with the same length as Source and all bytes copied over.
217217
/// No conversion of any sort is being applied to the bytes.
218218
/// </returns>
219-
/// <remarks>
220-
/// This is a wrapper for StringOf of Sysutils
221-
/// </remarks>
222219
function BytesToRawString(const Source: TBytes): RawByteString; inline;
223220

224221
/// <summary>
@@ -652,7 +649,9 @@ procedure ProtectString(var Source: WideString); overload;
652649

653650
function BytesToRawString(const Source: TBytes): RawByteString;
654651
begin
655-
result := RawByteString(StringOf(Source));
652+
SetLength(Result, Length(Source));
653+
if Length(Source) > 0 then
654+
Move(Source[low(Source)], Result[low(Result)], Length(Source)); // Copy bytes directly
656655
end;
657656

658657
function RawStringToBytes(const RawString: RawByteString): TBytes;

0 commit comments

Comments
 (0)