Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Nov : class design bug in TIdHash
| Subject: | class design bug in TIdHash |
| Posted by: | "Philip von Melle" (philip.vonmel..@globetrotter.de) |
| Date: | 19 Nov 2006 03:33:14 |
The current Indy 10.1.6 snapshot does not compile under .NET because line
3562 in IdFTP.pas generates a compiler error: "Potentially polymorphic
constructor calls must be virtual". This also highlights a bug in the Win32
code (where it does not generate a compiler error, though):
This comes from creating the desired hash class from a class referece
LHashClass: TIDHashClass.
TIdHash has no constructor of its own but TIdHashMessageDigest has one.
TIdHashMessageDigest4 also has one which is decleared virtual and with a
different signature than TIdHashMessageDigest.
Now, my opion is that TIdHash needs a virtual constructor (which is empty).
and hence TIdHashSHA1, TIdMessageDigest2 and TIdHashMessageDigest4 need to
override it. Finally TIdHashMessageDigest needs to declare its constructor
as reintroduce; overload; (or be renamed) for everything to work fine.
Due to this under Win32 the constructors of TIdHashMessageDigest2/4 are
never called when created polymorphically from a class reference. In
TIdHashMessageDigest2 this gives a range check error because FCBuffer is
never initialized to its correct length and in TIdHashMessageDigest4 this
only happens by chance in ReadTIdBytesFromStream and a StreamHelper but not
from within the constructor.