kwo pushed a commit to branch master.

http://git.enlightenment.org/e16/e16.git/commit/?id=6c0eb8620a7bee1f21eebaac182088df7f59a619

commit 6c0eb8620a7bee1f21eebaac182088df7f59a619
Author: Kim Woelders <k...@woelders.dk>
Date:   Sat Jul 17 13:35:54 2021 +0200

    Backgrounds: Fix bad list operation in CB_ConfigureDelBG()
    
    If ever we would delete the last background in the list we would get a
    segv.
    However, this will never occur as the None background is always the last
    in the list and we will never delete it.
    
    This can be a bit difficult to comprehend for static analysis tools so
    eliminate the offending list operation.
---
 src/backgrounds.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/backgrounds.c b/src/backgrounds.c
index 965b84ca..ca7532c6 100644
--- a/src/backgrounds.c
+++ b/src/backgrounds.c
@@ -1572,8 +1572,8 @@ static void
 CB_ConfigureDelBG(Dialog * d, int val, void *data __UNUSED__)
 {
    BgDlgData          *dd = DLG_DATA_GET(d, BgDlgData);
-   Background         *bg;
    int                 lower, upper;
+   Background         *bg, *bgn;
 
    bg = LIST_CHECK(Background, &bg_list, dd->bg);
    if (!bg)
@@ -1581,17 +1581,16 @@ CB_ConfigureDelBG(Dialog * d, int val, void *data 
__UNUSED__)
    if (BackgroundIsNone(bg))
       return;
 
-   bg = LIST_NEXT(Background, &bg_list, bg);
-   if (!bg)
-      bg = LIST_PREV(Background, &bg_list, bg);
+   bgn = LIST_NEXT(Background, &bg_list, bg);
+   if (!bgn)
+      bgn = LIST_PREV(Background, &bg_list, bg);
 
-   DeskBackgroundSet(DesksGetCurrent(), bg);
+   DeskBackgroundSet(DesksGetCurrent(), bgn);
 
    if (val == 0)
-      BackgroundDestroy(dd->bg);
+      BackgroundDestroy(bg);
    else
-      BackgroundDelete(dd->bg);
-   dd->bg = NULL;
+      BackgroundDelete(bg);
 
    DialogItemSliderGetBounds(dd->bg_sel_slider, &lower, &upper);
    upper -= 4;
@@ -1599,7 +1598,8 @@ CB_ConfigureDelBG(Dialog * d, int val, void *data 
__UNUSED__)
    if (dd->bg_sel_sliderval > upper)
       DialogItemSliderSetVal(dd->bg_sel_slider, upper);
 
-   BgDialogSetNewCurrent(d, bg);
+   dd->bg = NULL;
+   BgDialogSetNewCurrent(d, bgn);
 
    autosave();
 }

-- 


Reply via email to