Skip to content

TBucketList throws access violations after Clear()

Summary

After TBucketList.Clear, other methods throw access violation

System Information

  • Operating system:
  • Processor architecture:
  • Compiler version:3.2.2
  • Device:Windows

Steps to reproduce

  • create any TBucketList
  • Clear() it
  • Add(any item,any data)

Example Project

program Project1;
uses contnrs;
var b:TBucketList;
begin
  b:=TBucketList.Create();
  b.Clear();
  b.Add(nil,nil);
end.

What is the current bug behavior?

Throws Access Violation at b.Add(nil,nil)

What is the expected (correct) behavior?

Should add item to bucket list. Works in Delphi.

Relevant logs and/or screenshots

Possible fixes

FILE: /fclbase/src/contnrs.pas

TCustomBucketList.Clear line 2596: SetLength(FBuckets,0); <-- sets FBuckets to NIL

TCustomBucketList.AddItem line 2521: B:=@FBuckets[ABucket]; <--- uses the NIL variable

TCustomBucetList.FindItem line 2570: B:=FBuckets[ABucket]; <--- also uses the NIL variable

Clear() should not zero the bucket count.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information