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]; r+=q[0]; g+=q[1]; b+=q[2]; a+=q[3];
} }
} }
p[0]= uint8_t(r/sq); int sq_tmp = sq ? sq : 1;//avoid division by zero
p[1]= uint8_t(g/sq); p[0]= uint8_t(r/sq_tmp);
p[2]= uint8_t(b/sq); p[1]= uint8_t(g/sq_tmp);
p[3]= uint8_t(a/sq); p[2]= uint8_t(b/sq_tmp);
p[3]= uint8_t(a/sq_tmp);
} }
} }
}else }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]; r+=q[0]; g+=q[1]; b+=q[2];
} }
} }
p[0]= uint8_t(r/sq); int sq_tmp = sq ? sq : 1;//avoid division by zero
p[1]= uint8_t(g/sq); p[0]= uint8_t(r/sq_tmp);
p[2]= uint8_t(b/sq); 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 ypos = y+ theight;
const int sb = height - theight - footerHeight; // paint scrollbar over full height of main box 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); frameBuffer->paintBoxRel(x+ width- 15,ypos, 15, sb, COL_MENUCONTENT_PLUS_1);
unsigned int listmaxshow_tmp = listmaxshow ? listmaxshow : 1;//avoid division by zero
int sbc= (((*chanlist).size()- 1)/ listmaxshow)+ 1; int sbc= (((*chanlist).size()- 1)/ listmaxshow_tmp)+ 1;
const int sbs= (selected/listmaxshow); const int sbs= (selected/listmaxshow_tmp);
if (sbc < 1) if (sbc < 1)
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; ypos = m_y + m_title_height + m_theight;
int sb = m_fheight * m_listmaxshow; int sb = m_fheight * m_listmaxshow;
m_frameBuffer->paintBoxRel(m_x + m_width - 15, ypos, 15, sb, COL_MENUCONTENT_PLUS_1); m_frameBuffer->paintBoxRel(m_x + m_width - 15, ypos, 15, sb, COL_MENUCONTENT_PLUS_1);
unsigned int tmp = m_listmaxshow ? m_listmaxshow : 1;//avoid division by zero
int sbc = ((max + offset - 1) / m_listmaxshow) + 1; int sbc = ((max + offset - 1) / tmp) + 1;
int sbs = ((selected + offset) / m_listmaxshow); int sbs = ((selected + offset) / tmp);
int sbh = 0; int sbh = 0;
if ((sbc > 0) && (sbc > sb-4)) if ((sbc > 0) && (sbc > sb-4))

View File

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