summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-07-17 13:35:54 +0200
committerKim Woelders <kim@woelders.dk>2021-07-17 15:20:53 +0200
commit6c0eb8620a7bee1f21eebaac182088df7f59a619 (patch)
tree766e00f7dd141625b7cd638c44adbc11f427d88a
parent1e0e63747f58e05f7d967be238b5d5b7db90f5ba (diff)
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.
-rw-r--r--src/backgrounds.c18
1 files 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
1572CB_ConfigureDelBG(Dialog * d, int val, void *data __UNUSED__) 1572CB_ConfigureDelBG(Dialog * d, int val, void *data __UNUSED__)
1573{ 1573{
1574 BgDlgData *dd = DLG_DATA_GET(d, BgDlgData); 1574 BgDlgData *dd = DLG_DATA_GET(d, BgDlgData);
1575 Background *bg;
1576 int lower, upper; 1575 int lower, upper;
1576 Background *bg, *bgn;
1577 1577
1578 bg = LIST_CHECK(Background, &bg_list, dd->bg); 1578 bg = LIST_CHECK(Background, &bg_list, dd->bg);
1579 if (!bg) 1579 if (!bg)
@@ -1581,17 +1581,16 @@ CB_ConfigureDelBG(Dialog * d, int val, void *data __UNUSED__)
1581 if (BackgroundIsNone(bg)) 1581 if (BackgroundIsNone(bg))
1582 return; 1582 return;
1583 1583
1584 bg = LIST_NEXT(Background, &bg_list, bg); 1584 bgn = LIST_NEXT(Background, &bg_list, bg);
1585 if (!bg) 1585 if (!bgn)
1586 bg = LIST_PREV(Background, &bg_list, bg); 1586 bgn = LIST_PREV(Background, &bg_list, bg);
1587 1587
1588 DeskBackgroundSet(DesksGetCurrent(), bg); 1588 DeskBackgroundSet(DesksGetCurrent(), bgn);
1589 1589
1590 if (val == 0) 1590 if (val == 0)
1591 BackgroundDestroy(dd->bg); 1591 BackgroundDestroy(bg);
1592 else 1592 else
1593 BackgroundDelete(dd->bg); 1593 BackgroundDelete(bg);
1594 dd->bg = NULL;
1595 1594
1596 DialogItemSliderGetBounds(dd->bg_sel_slider, &lower, &upper); 1595 DialogItemSliderGetBounds(dd->bg_sel_slider, &lower, &upper);
1597 upper -= 4; 1596 upper -= 4;
@@ -1599,7 +1598,8 @@ CB_ConfigureDelBG(Dialog * d, int val, void *data __UNUSED__)
1599 if (dd->bg_sel_sliderval > upper) 1598 if (dd->bg_sel_sliderval > upper)
1600 DialogItemSliderSetVal(dd->bg_sel_slider, upper); 1599 DialogItemSliderSetVal(dd->bg_sel_slider, upper);
1601 1600
1602 BgDialogSetNewCurrent(d, bg); 1601 dd->bg = NULL;
1602 BgDialogSetNewCurrent(d, bgn);
1603 1603
1604 autosave(); 1604 autosave();
1605} 1605}