View Issue Details

IDProjectCategoryView StatusLast Update
0037839LazarusLCLpublic2020-09-30 11:24
ReporterZdravko Gabrovski Assigned ToZeljan Rikalo  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformAllOSAll 
Product Version2.1 (SVN) 
Summary0037839: AV in "Alt+TAB" When TCheckComboBox is dropped down
DescriptionIf you have a TCheckComboBox dropped down and press "Alt+Tab" to go to other application, it will raise "SigSeg failed(AV)"
The problem comes from function TCustomCheckCombo.GetItemEnabled(AIndex: Integer): Boolean; in comboex.inc file, because AIndex is = -1 in that moment.
I just add sanity check in all methods in this include unit and now problem dissapere.
Steps To ReproduceRestore attached project, compile it under trunk lazarus build. Run it.
Just click CheckComboBox to drop down, and when the list is dropped down press Alt+tab.
Project will raise SigSeg exception.
Additional InformationI tested under Windows but for sure will bi similar problem under all widgetsets.
TagsNo tags attached.
Fixed in Revision63941
LazTarget-
WidgetsetWin32/Win64
Attached Files

Activities

Zdravko Gabrovski

2020-09-29 15:08

reporter  

comboex.diff (2,095 bytes)   
Index: lcl/include/comboex.inc
===================================================================
--- lcl/include/comboex.inc	(revision 63906)
+++ lcl/include/comboex.inc	(working copy)
@@ -838,6 +838,8 @@
 
 function TCustomCheckCombo.GetChecked(AIndex: Integer): Boolean;
 begin
+  if Aindex < 0 then
+    Exit( False );
   Result:=(TCheckComboItemState(Items.Objects[AIndex]).State=cbChecked);
 end;
 
@@ -853,21 +855,29 @@
 
 function TCustomCheckCombo.GetItemEnabled(AIndex: Integer): Boolean;
 begin
+  if Aindex < 0 then
+    Exit( False );
   Result:=TCheckComboItemState(Items.Objects[AIndex]).Enabled;
 end;
 
 function TCustomCheckCombo.GetObject(AIndex: Integer): TObject;
 begin
+  if Aindex < 0 then
+    Exit( nil );
   Result:=TCheckComboItemState(Items.Objects[AIndex]).Data;
 end;
 
 function TCustomCheckCombo.GetState(AIndex: Integer): TCheckBoxState;
 begin
+  if Aindex < 0 then
+    Exit( cbGrayed );
   Result:=TCheckComboItemState(Items.Objects[AIndex]).State;
 end;
 
 procedure TCustomCheckCombo.SetChecked(AIndex: Integer; AValue: Boolean);
 begin
+  if Aindex < 0 then
+    Exit;
   if AValue=(TCheckComboItemState(Items.Objects[AIndex]).State=cbChecked) then exit;
   if AValue
     then TCheckComboItemState(Items.Objects[AIndex]).State:=cbChecked
@@ -880,6 +890,8 @@
 
 procedure TCustomCheckCombo.SetItemEnabled(AIndex: Integer; AValue: Boolean);
 begin
+  if Aindex < 0 then
+    Exit;
   if TCheckComboItemState(Items.Objects[AIndex]).Enabled=AValue then exit;
   TCheckComboItemState(Items.Objects[AIndex]).Enabled:=AValue;
   if AIndex=ItemIndex then
@@ -888,11 +900,15 @@
 
 procedure TCustomCheckCombo.SetObject(AIndex: Integer; AValue: TObject);
 begin
+  if Aindex < 0 then
+    Exit;
   TCheckComboItemState(Items.Objects[AIndex]).Data:=AValue;
 end;
 
 procedure TCustomCheckCombo.SetState(AIndex: Integer; AValue: TCheckBoxState);
 begin
+  if Aindex < 0 then
+    Exit;
   if TCheckComboItemState(Items.Objects[AIndex]).State=AValue then exit;
   TCheckComboItemState(Items.Objects[AIndex]).State:=AValue;
   if Assigned(FOnItemChange) then
comboex.diff (2,095 bytes)   
CheckComboBug.7z (52,917 bytes)

Zeljan Rikalo

2020-09-29 16:34

developer   ~0125959

IMO, that patch is wrong, hides programmer bug.

Serge Anvarov

2020-09-29 22:38

reporter   ~0125969

In my opinion this patch is enough:
TCustomCheckCombo.Select.diff (473 bytes)   
Index: lcl/include/comboex.inc
===================================================================
--- lcl/include/comboex.inc	(revision 63938)
+++ lcl/include/comboex.inc	(working copy)
@@ -805,7 +805,7 @@
   {$ENDIF}
   if not FRejectToggleOnSelect then
     begin
-      if ItemEnabled[ItemIndex] then Toggle(ItemIndex);
+      if (ItemIndex >= 0) and ItemEnabled[ItemIndex] then Toggle(ItemIndex);
       FRejectToggleOnSelect:=True;
     end;
   FDropped:=False;

jamie philbrook

2020-09-29 22:57

reporter   ~0125970

Yes, first patch is totally wrong, that not only hides an issue it also does not set the RESULTS on the return.

Second patch looks good.

Zdravko Gabrovski

2020-09-30 00:23

reporter   ~0125971

I have no time to debug from where the problem comes.
I Just add a sanity check.
in Serge patch he did the same but before toggle setstate.

jamie philbrook

2020-09-30 02:18

reporter   ~0125973

Yes but it's better to handle it with simple code which makes it clearer.

 Btw, I did some work on the matching ComboboxEx but didn't submit it due to other problems in the LCL code which now seem's to be fixed, so maybe I'll submit a patch in a different report someday ;)

Zeljan Rikalo

2020-09-30 09:56

developer   ~0125976

That Serge's patch looks ok and clean.

Zeljan Rikalo

2020-09-30 09:59

developer   ~0125977

@Serge tnx for the patch. Please close if ok.

Zdravko Gabrovski

2020-09-30 11:24

reporter   ~0125979

Thanks to everybody!

Zdravko Gabrovski

2020-09-30 11:24

reporter   ~0125980

Seems working, closing.

Issue History

Date Modified Username Field Change
2020-09-29 15:08 Zdravko Gabrovski New Issue
2020-09-29 15:08 Zdravko Gabrovski File Added: comboex.diff
2020-09-29 15:08 Zdravko Gabrovski File Added: CheckComboBug.7z
2020-09-29 16:34 Zeljan Rikalo Note Added: 0125959
2020-09-29 22:38 Serge Anvarov Note Added: 0125969
2020-09-29 22:38 Serge Anvarov File Added: TCustomCheckCombo.Select.diff
2020-09-29 22:57 jamie philbrook Note Added: 0125970
2020-09-30 00:23 Zdravko Gabrovski Note Added: 0125971
2020-09-30 02:18 jamie philbrook Note Added: 0125973
2020-09-30 09:56 Zeljan Rikalo Note Added: 0125976
2020-09-30 09:58 Zeljan Rikalo Assigned To => Zeljan Rikalo
2020-09-30 09:58 Zeljan Rikalo Status new => resolved
2020-09-30 09:58 Zeljan Rikalo Resolution open => fixed
2020-09-30 09:58 Zeljan Rikalo Fixed in Revision => 63941
2020-09-30 09:59 Zeljan Rikalo LazTarget => -
2020-09-30 09:59 Zeljan Rikalo Widgetset Win32/Win64 => Win32/Win64
2020-09-30 09:59 Zeljan Rikalo Note Added: 0125977
2020-09-30 11:24 Zdravko Gabrovski Note Added: 0125979
2020-09-30 11:24 Zdravko Gabrovski Status resolved => closed
2020-09-30 11:24 Zdravko Gabrovski Note Added: 0125980