View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0033448 | FPC | Database | public | 2018-03-17 15:50 | 2018-03-17 22:24 |
Reporter | wp | Assigned To | Michael Van Canneyt | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Product Version | 3.1.1 | Product Build | |||
Target Version | 3.2.0 | Fixed in Version | 3.1.1 | ||
Summary | 0033448: BufDataset crashing due to missing Index | ||||
Description | I came across this issue in Lazarus with this sequence of steps: - Add a TBufDataset to a form - Add a IndexDef to the dataset by using the IndexDefs' '...' button - In the object inspector, click on the TBufDataset --> crash with an unspecified access violation. According to a stack trace the crash happens in TBufDataset.GetIndexName. From this information I built the following simpler test program: -------------------------------- program project1; {$mode objfpc}{$H+} uses Classes, db, bufdataset; var ds: TBufDataset; begin WriteLn('Starting...'); ds := TBufDataset.Create(nil); try ds.Name := 'BufDataset1Name'; ds.IndexDefs.Add('','', []); WriteLn(ds.IndexName); // <------------ crash here finally ds.Free; end; ReadLn; end. ---------------------------------- The getter of TBufDataset.IndexName -------------------------------------------- function TCustomBufDataset.GetIndexName: String; begin if FIndexes.Count>0 then result := CurrentIndexBuf.Name else result := FIndexName; end; --------------------------------------------- calls the getter of CurrentIndexBuf ----------------------------------------- function TCustomBufDataset.GetCurrentIndexBuf: TBufIndex; begin if Assigned(FCurrentIndexDef) then Result:=FCurrentIndexDef.BufferIndex else Result:=Nil; end; ------------------------------------------ which happens to be nil in this particular situation. With a check against nil in GetIndexName the crash can be avoided: ------------------------------------------- function TCustomBufDataset.GetIndexName: String; begin if (FIndexes.Count>0) and Assigned(CurrentIndexBuf) then result := CurrentIndexBuf.Name else result := FIndexName; end; ------------------------------------------ I am not sure, however, if this fix shadows another error. | ||||
Additional Information | The bug does not happen in FPC 3.0.4. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | 38549 | ||||
FPCOldBugId | |||||
FPCTarget | |||||
Attached Files |
|
|
bufdataset.pas.patch (404 bytes)
Index: bufdataset.pas =================================================================== --- bufdataset.pas (revision 38547) +++ bufdataset.pas (working copy) @@ -3028,7 +3028,7 @@ function TCustomBufDataset.GetIndexName: String; begin - if FIndexes.Count>0 then + if (FIndexes.Count>0) and (CurrentIndexBuf <> nil) then result := CurrentIndexBuf.Name else result := FIndexName; |
|
Consequence of a refactoring of the indexes. Thanks for the patch! |
|
Thanks |
Date Modified | Username | Field | Change |
---|---|---|---|
2018-03-17 15:50 | wp | New Issue | |
2018-03-17 15:50 | wp | File Added: bufdataset.pas.patch | |
2018-03-17 16:07 | Michael Van Canneyt | Assigned To | => Michael Van Canneyt |
2018-03-17 16:07 | Michael Van Canneyt | Status | new => assigned |
2018-03-17 16:11 | Michael Van Canneyt | Fixed in Revision | => 38549 |
2018-03-17 16:11 | Michael Van Canneyt | Note Added: 0107200 | |
2018-03-17 16:11 | Michael Van Canneyt | Status | assigned => resolved |
2018-03-17 16:11 | Michael Van Canneyt | Fixed in Version | => 3.1.1 |
2018-03-17 16:11 | Michael Van Canneyt | Resolution | open => fixed |
2018-03-17 16:11 | Michael Van Canneyt | Target Version | => 3.2.0 |
2018-03-17 22:24 | wp | Note Added: 0107218 | |
2018-03-17 22:24 | wp | Status | resolved => closed |