TFPHashList.FindIndexOf fails if Item = nil
Original Reporter info from Mantis: ruewa
-
Reporter name:
Original Reporter info from Mantis: ruewa
- Reporter name:
Description:
I'm not quite sure, whether this is a bug or an undocumented, but intended (or even necessary?) restriction.
TFPHashList accepts duplicate keys (I wasn't aware of, is this intended?).
To avoid adding duplicates, I used the following condition:
if HashList.FindIndexOf(s) < 0 then HashList.Add(s, p);
This fails, if p = nil: The key will be added, but a subsequent FindIndexOf returns -1.
This behaviour is coded in TFPHashList.FindInternal (unit ContNrs, line 1482):
if assigned({THashItem.}Data) and ... then exit {search iteration}
AFAIKS the internal processing of the Hashlist does not depend on the assignement of this data pointer, so if this behaviour should be intended, I can't see any reason or advantage, the more as TFPHashList.Add() doesn't reject a nil pointer.
Steps to reproduce:
See the attached demo program
Mantis conversion info:
- Mantis ID: 26800
- OS: Linux
- OS Build: Debian Wheezy
- Build: 45510
- Platform: AMD64
- Version: 1.2.4
- Fixed in version: 3.1.1
- Fixed in revision: 1152 (#6d17d83b)
- Target version: 3.0.0