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.
This commit is contained in:
Kim Woelders 2021-07-17 13:35:54 +02:00
parent 1e0e63747f
commit 6c0eb8620a
1 changed files with 9 additions and 9 deletions

View File

@ -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();
}