Fixed possible segfault when showing scrollbar in search result lists

A segfault is possible if numSteps is greater than height in
"cRecMenu::createScrollbar()".
This commit is contained in:
kamel5 2022-04-07 13:31:15 +02:00
parent e2d67769dc
commit eb259fb961

View File

@ -123,8 +123,7 @@ void cRecMenu::InitMenu(bool complete) {
width -= scrollbarWidth + border; width -= scrollbarWidth + border;
osdManager.releasePixmap(pixmapScrollBar); osdManager.releasePixmap(pixmapScrollBar);
pixmapScrollBar = NULL; pixmapScrollBar = NULL;
delete imgScrollBar; DELETENULL(imgScrollBar);
imgScrollBar = NULL;
} }
osdManager.releasePixmap(pixmap); osdManager.releasePixmap(pixmap);
pixmap = NULL; pixmap = NULL;
@ -597,7 +596,7 @@ void cRecMenu::DrawScrollBar(void) {
int totalNumItems = GetTotalNumMenuItems(); int totalNumItems = GetTotalNumMenuItems();
if (!totalNumItems) if (!totalNumItems)
return; return;
if (imgScrollBar == NULL) { if (!imgScrollBar) {
int scrollBarImgHeight = (pixmapScrollBar->ViewPort().Height() - 8) * numItems / totalNumItems; int scrollBarImgHeight = (pixmapScrollBar->ViewPort().Height() - 8) * numItems / totalNumItems;
imgScrollBar = createScrollbar(pixmapScrollBar->ViewPort().Width() - 8, scrollBarImgHeight, theme.Color(clrHighlight), theme.Color(clrHighlightBlending)); imgScrollBar = createScrollbar(pixmapScrollBar->ViewPort().Width() - 8, scrollBarImgHeight, theme.Color(clrHighlight), theme.Color(clrHighlightBlending));
} }
@ -678,18 +677,14 @@ eRecMenuState cRecMenu::ProcessKey(eKeys Key) {
cImage *cRecMenu::createScrollbar(int width, int height, tColor clrBgr, tColor clrBlend) { cImage *cRecMenu::createScrollbar(int width, int height, tColor clrBgr, tColor clrBlend) {
cImage *image = new cImage(cSize(width, height)); cImage *image = new cImage(cSize(width, height));
image->Fill(clrBgr); image->Fill(clrBgr);
if (config.style != eStyleFlat) { if (height >= 32 && config.style != eStyleFlat) {
int numSteps = 64; int numSteps = 64;
int alphaStep = 0x03; int alphaStep = 0x03;
if (height < 30) if (height < 100) {
return image;
else if (height < 100) {
numSteps = 32; numSteps = 32;
alphaStep = 0x06; alphaStep = 0x06;
} }
int stepY = 0.5*height / numSteps; int stepY = std::max(1, (int)(0.5 * height / numSteps));
if (stepY == 0)
stepY = 1;
int alpha = 0x40; int alpha = 0x40;
tColor clr; tColor clr;
for (int i = 0; i < numSteps; i++) { for (int i = 0; i < numSteps; i++) {