Skip to content

Commit fe91906

Browse files
committed
Improve LEDMeterMode_draw() limit check after data type changes
Signed-off-by: Kang-Che Sung <[email protected]>
1 parent 4322ad5 commit fe91906

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

Meter.c

+19-17
Original file line numberDiff line numberDiff line change
@@ -316,26 +316,28 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
316316
attrset(CRT_colors[LED_COLOR]);
317317
const char* caption = Meter_getCaption(this);
318318
mvaddstr(yText, x, caption);
319-
int xx = x + (int)strlen(caption);
320-
size_t len = RichString_sizeVal(out);
321-
for (size_t i = 0; i < len; i++) {
322-
int c = RichString_getCharVal(out, i);
323-
if (c >= '0' && c <= '9') {
324-
if (xx - x + 4 > w)
325-
break;
326-
327-
LEDMeterMode_drawDigit(xx, y, c - '0');
328-
xx += 4;
329-
} else {
330-
if (xx - x + 1 > w)
331-
break;
319+
if (strlen(caption) <= INT_MAX - (unsigned int)x) {
320+
int xx = x + (int)strlen(caption);
321+
size_t len = RichString_sizeVal(out);
322+
for (size_t i = 0; i < len; i++) {
323+
int c = RichString_getCharVal(out, i);
324+
if (c >= '0' && c <= '9') {
325+
if (xx - x + 4 > w)
326+
break;
327+
328+
LEDMeterMode_drawDigit(xx, y, c - '0');
329+
xx += 4;
330+
} else {
331+
if (xx - x + 1 > w)
332+
break;
332333
#ifdef HAVE_LIBNCURSESW
333-
const cchar_t wc = { .chars = { c, '\0' }, .attr = 0 }; /* use LED_COLOR from attrset() */
334-
mvadd_wch(yText, xx, &wc);
334+
const cchar_t wc = { .chars = { c, '\0' }, .attr = 0 }; /* use LED_COLOR from attrset() */
335+
mvadd_wch(yText, xx, &wc);
335336
#else
336-
mvaddch(yText, xx, c);
337+
mvaddch(yText, xx, c);
337338
#endif
338-
xx += 1;
339+
xx += 1;
340+
}
339341
}
340342
}
341343
attrset(CRT_colors[RESET_COLOR]);

0 commit comments

Comments
 (0)