fgl TFPGLMap crashes after repeated insertions of new elements
Original Reporter info from Mantis: tom_at_work
-
Reporter name: Thomas Schatzl
Original Reporter info from Mantis: tom_at_work
- Reporter name: Thomas Schatzl
Description:
The program
{$mode objfpc} {$H+}
uses fgl,sysutils;
const strs : array[0..16] of integer = (1,2,2,7,0,12,3,4,5,3,6,7,8,9,0,3,4);
type
TInterestingData = integer;
TMySet = specialize TFPGmap<integer, TInterestingData>;
function mycompare(const a,b : integer) : integer;
begin
result := a-b;
end;
var
s : TMySet;
idx, i,j : Integer;
b : TInterestingData;
begin
s := TMySet.Create(); s.sorted := false;
s.OnCompare := @mycompare;
for i := low(strs) to high(strs) do begin
idx := s.IndexOf(strs[i]);
writeln(s.count, ' ', s.capacity);
if (idx <> -1) then begin
b := s[strs[i]];
end else begin
b := i;
s[strs[i]] := b;
end;
// do something with existing interesting data
writeln(b * b);
end;
s.Free;
end.
gives the following output:
0 0
0
1 4
1
2 4
4
2 4
9
3 4
16
4 4
25
5 12
36
6 12
49
7 12
64
8 12
9
8 12
100
9 12
49
9 12
144
10 12
169
11 12
An unhandled exception occurred at $000000001000061C :
EAccessViolation : Access violation<br/>
$000000001000061C line 900 of test.pas
$0000000010000E38 line 29 of test.pas
$00000000100003CC
Notice the output for s.count and capacity, it seems to only occur while the TFPGLMap gets expanded (it uses an internal array which is expanded by 4 items there is no room left).
This behaviour is reproducible with different types used for specializing the class, however not always exactly when expanding for the third time, but always at a multiple of 4.
Mantis conversion info:
- Mantis ID: 9672
- Version: 2.3.1
- Fixed in version: 2.2.2
- Fixed in revision: 9003 (#550e97d7)
- Target version: 2.4.0