function ToBytes(Short) @ IdGlobal.pas is wrong.

Giganews Newsgroups
Subject: function ToBytes(Short) @ IdGlobal.pas is wrong.
Posted by:  Flier Lu (flier.…@gmail.com)
Date: Tue, 28 Jun 2005

indy 10.0.52, System\IdGlobal.pas, line 2395

function ToBytes(const AValue: Short): TIdBytes; overload;
begin
  {$IFDEF DotNet}
  Result := System.BitConverter.GetBytes(AValue);
  {$ELSE}
  SetLength(Result, SizeOf(Shortint));
  PShortint(@Result[0])^ := AValue;
  {$ENDIF}
end;

this function is wrong, because 'short' is not 'shortint', the line

SetLength(Result, SizeOf(Shortint));
PShortint(@Result[0])^ := AValue;

should be

SetLength(Result, SizeOf(Short));
PShort(@Result[0])^ := AValue;

waste lots of time to locate this :S

Replies