Skip to content

Commit

Permalink
Fixes opentx#5055: infinite loop in lcdDrawFilledRect() when h para…
Browse files Browse the repository at this point in the history
…meter is bigger than 127. Similar fixes in other places. (opentx#5058)
  • Loading branch information
projectkk2glider authored and bsongis committed Aug 15, 2017
1 parent 824f393 commit a167e9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 8 additions & 5 deletions radio/src/gui/128x64/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,12 @@ void lcdDrawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat, LcdFla
void lcdDrawFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags att)
{
#if defined(CPUM64)
for (scoord_t i=y; i<y+h; i++) {
for (scoord_t i=y; i<(scoord_t)(y+h); i++) {
lcdDrawHorizontalLine(x, i, w, pat, att);
pat = (pat >> 1) + ((pat & 1) << 7);
}
#else
for (scoord_t i=y; i<y+h; i++) {
for (scoord_t i=y; i<(scoord_t)(y+h); i++) { // cast to scoord_t needed otherwise (y+h) is promoted to int (see #5055)
if ((att&ROUND) && (i==y || i==y+h-1))
lcdDrawHorizontalLine(x+1, i, w-2, pat, att);
else
Expand Down Expand Up @@ -1516,7 +1516,7 @@ void NAME(coord_t x, coord_t y, TYPE img, uint8_t idx, LcdFlags att) \
q += idx*w*hb; \
for (uint8_t yb = 0; yb < hb; yb++) { \
uint8_t *p = &displayBuf[(y / 8 + yb) * LCD_W + x]; \
for (coord_t i=0; i<w; i++){ \
for (uint8_t i=0; i<w; i++){ \
uint8_t b = READ_BYTE(q); \
q++; \
ASSERT_IN_DISPLAY(p); \
Expand Down Expand Up @@ -1554,9 +1554,12 @@ void lcdDrawPoint(coord_t x, coord_t y, LcdFlags att)
}
}

void lcdInvertLine(int8_t y)
void lcdInvertLine(int8_t line)
{
uint8_t *p = &displayBuf[y * LCD_W];
if (line < 0) return;
if (line >= LCD_LINES) return;

uint8_t *p = &displayBuf[line * LCD_W];
for (coord_t x=0; x<LCD_W; x++) {
ASSERT_IN_DISPLAY(p);
*p++ ^= 0xff;
Expand Down
11 changes: 7 additions & 4 deletions radio/src/gui/212x64/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void lcdPutPattern(coord_t x, coord_t y, const uint8_t * pattern, uint8_t width,
uint8_t lines = (height+7)/8;
assert(lines <= 5);

for (int8_t i=0; i<width+2; i++) {
for (int8_t i=0; i<(int8_t)(width+2); i++) {
if (x<LCD_W) {
uint8_t b[5] = { 0 };
if (i==0) {
Expand Down Expand Up @@ -120,7 +120,7 @@ void lcdPutPattern(coord_t x, coord_t y, const uint8_t * pattern, uint8_t width,
}
}

for (int8_t j=-1; j<=height; j++) {
for (int8_t j=-1; j<=(int8_t)(height); j++) {
bool plot;
if (j < 0 || ((j == height) && !(FONTSIZE(flags) == SMLSIZE))) {
plot = false;
Expand Down Expand Up @@ -484,7 +484,7 @@ void lcdDrawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat, LcdFla
#if !defined(BOOT)
void lcdDrawFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags att)
{
for (scoord_t i=y; i<y+h; i++) {
for (scoord_t i=y; i<(scoord_t)(y+h); i++) {
if ((att&ROUND) && (i==y || i==y+h-1))
lcdDrawHorizontalLine(x+1, i, w-2, pat, att);
else
Expand Down Expand Up @@ -873,6 +873,9 @@ void lcdDrawVerticalLine(coord_t x, scoord_t y, scoord_t h, uint8_t pat, LcdFlag

void lcdInvertLine(int8_t line)
{
if (line < 0) return;
if (line >= LCD_LINES) return;

uint8_t *p = &displayBuf[line * 4 * LCD_W];
for (coord_t x=0; x<LCD_W*4; x++) {
ASSERT_IN_DISPLAY(p);
Expand All @@ -889,7 +892,7 @@ void lcdDraw1bitBitmap(coord_t x, coord_t y, const pm_uchar * img, uint8_t idx,
bool inv = (att & INVERS) ? true : (att & BLINK ? BLINK_ON_PHASE : false);
q += idx*w*hb;
for (uint8_t yb = 0; yb < hb; yb++) {
for (coord_t i=0; i<w; i++) {
for (uint8_t i=0; i<w; i++) {
uint8_t b = pgm_read_byte(q++);
uint8_t val = inv ? ~b : b;
for (int k=0; k<8; k++) {
Expand Down

0 comments on commit a167e9f

Please sign in to comment.