[fpc-devel] crash with TCuckooD2<string, string>

mailinglists at geldenhuys.co.uk mailinglists at geldenhuys.co.uk
Wed Apr 8 21:58:27 CEST 2026


On 2026-04-08 13:10, Martin Frb via fpc-devel wrote:
> 
> The crash happens after "Run2" did
>   Dict.clear;
> 
> when it attempts to add a new element.


Funny that, I hit a similar problem. I've found and fixed the issue:

Merge Request created here:
   https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/1422


Saying that, there were also a few issues in your test program:

1. My line numbers might not match your exactly. in the test at line 
54/201: if not
Dict.Count = AnExp is evaluated as (not Dict.Count) = AnExp (bitwise 
NOT, not
logical) due to Pascal operator precedence, so CheckCount never actually 
detects
a wrong count. That's a test bug unrelated to the crash, but worth 
noting.

Both CheckCount procedures have the same bug:

   - test_dict.pas:54 (in Run)
   - test_dict.pas:201 (in Run2)

   if not Dict.Count = AnExp then
                                                                          
                                          should be:

   if Dict.Count <> AnExp then


2. The test itself has wrong expected values in the CheckCount calls
immediately after Dict.Clear — they were always silently passing due
to the not bug. Lines 125 and 267 both pass 101 but the count should
be 0 after a clear:

  122    for i := -99 to  -1 do CheckNot(i);
  123
  124    Dict.Clear;
  125 -  CheckCount(101);
  125 +  CheckCount(0);


  264    for i := -99 to  -1 do CheckNot(i);
  265
  266    Dict.Clear;
  267 -  CheckCount(101);
  267 +  CheckCount(0);


3. Line 154: after AddOrSetValue('999', 'A'), the dictionary has 3
entries (-999, 998, 999), not 2. The AddOrSetValue for '999' adds a
new key (the dict was cleared). Same issue in Run2.

  151      raise Exception.Create('TryOrSet failed');
  152    if Dict['998'] <> 'B' then
  153      raise Exception.Create('TryOrSet failed');
  154 -  CheckCount(2);
  154 +  CheckCount(3);


  293      raise Exception.Create('TryOrSet failed');
  294    if Dict['998'] <> 'B' then
  295      raise Exception.Create('TryOrSet failed');
  296 -  CheckCount(2);
  296 +  CheckCount(3);


After that, the test program runs without any crash or failures. :-)


Regards,
   Graeme


More information about the fpc-devel mailing list