avoid division by zero

This commit is contained in:
Jacek Jendrzej
2016-04-21 18:08:17 +02:00
parent 71adac0a0b
commit 49c86a38b4
4 changed files with 24 additions and 18 deletions

View File

@@ -774,10 +774,11 @@ unsigned char * CPictureViewer::int_Resize(unsigned char *orgin, int ox, int oy,
r+=q[0]; g+=q[1]; b+=q[2]; a+=q[3];
}
}
p[0]= uint8_t(r/sq);
p[1]= uint8_t(g/sq);
p[2]= uint8_t(b/sq);
p[3]= uint8_t(a/sq);
int sq_tmp = sq ? sq : 1;//avoid division by zero
p[0]= uint8_t(r/sq_tmp);
p[1]= uint8_t(g/sq_tmp);
p[2]= uint8_t(b/sq_tmp);
p[3]= uint8_t(a/sq_tmp);
}
}
}else
@@ -796,9 +797,10 @@ unsigned char * CPictureViewer::int_Resize(unsigned char *orgin, int ox, int oy,
r+=q[0]; g+=q[1]; b+=q[2];
}
}
p[0]= uint8_t(r/sq);
p[1]= uint8_t(g/sq);
p[2]= uint8_t(b/sq);
int sq_tmp = sq ? sq : 1;//avoid division by zero
p[0]= uint8_t(r/sq_tmp);
p[1]= uint8_t(g/sq_tmp);
p[2]= uint8_t(b/sq_tmp);
}
}
}

View File

@@ -2161,9 +2161,9 @@ void CChannelList::paintBody()
const int ypos = y+ theight;
const int sb = height - theight - footerHeight; // paint scrollbar over full height of main box
frameBuffer->paintBoxRel(x+ width- 15,ypos, 15, sb, COL_MENUCONTENT_PLUS_1);
int sbc= (((*chanlist).size()- 1)/ listmaxshow)+ 1;
const int sbs= (selected/listmaxshow);
unsigned int listmaxshow_tmp = listmaxshow ? listmaxshow : 1;//avoid division by zero
int sbc= (((*chanlist).size()- 1)/ listmaxshow_tmp)+ 1;
const int sbs= (selected/listmaxshow_tmp);
if (sbc < 1)
sbc = 1;

View File

@@ -1137,9 +1137,9 @@ printf("CUpnpBrowserGui::paintItem:s selected %d max %d offset %d\n", selected,
ypos = m_y + m_title_height + m_theight;
int sb = m_fheight * m_listmaxshow;
m_frameBuffer->paintBoxRel(m_x + m_width - 15, ypos, 15, sb, COL_MENUCONTENT_PLUS_1);
int sbc = ((max + offset - 1) / m_listmaxshow) + 1;
int sbs = ((selected + offset) / m_listmaxshow);
unsigned int tmp = m_listmaxshow ? m_listmaxshow : 1;//avoid division by zero
int sbc = ((max + offset - 1) / tmp) + 1;
int sbs = ((selected + offset) / tmp);
int sbh = 0;
if ((sbc > 0) && (sbc > sb-4))

View File

@@ -221,12 +221,15 @@ int paintButtons( const button_label_ext * const content,
}
if (spacing >= 0)
{ /* add half of the inter-object space to the */
spacing /= count_labels; /* left and right (this might break vertical */
{
int tmp = count_labels ? count_labels : 1;//avoid division by zero
/* add half of the inter-object space to the */
spacing /= tmp; /* left and right (this might break vertical */
x_button += spacing / 2; /* alignment, but nobody is using this (yet) */
} /* and I'm don't know how it should work. */
else
{
w_text = w_text ? w_text : 1;
/* shorten captions relative to their length */
for (int i = 0; i < cnt; i++)
fwidth[i] = (fwidth[i] * (w_text + spacing)) / w_text; /* spacing is negative...*/
@@ -410,8 +413,9 @@ int paintButtons( const int &x,
else
{
/* shorten captions relative to their length */
int tmp = w_text ? w_text : 1;//avoid division by zero
for (i = 0; i < cnt; i++)
fwidth[i] = (fwidth[i] * (w_text + spacing)) / w_text; /* spacing is negative...*/
fwidth[i] = (fwidth[i] * (w_text + spacing)) / tmp; /* spacing is negative...*/
spacing = 0;
}