aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-08 09:27:16 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-12 16:31:55 +0000
commitf1b4bf1275c653c5d091e64abe48d224e3b63a25 (patch)
treeed1eacb4f8d4990ac8305525ab01838ff89c2b70
parentbox-drawing: {h,v}line() + rect(): ensure *end* row/col is >= 0 (diff)
box-drawing: LIGHT ARC: ensure row+col are within range
-rw-r--r--box-drawing.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/box-drawing.c b/box-drawing.c
index 580f487b..0fb3be73 100644
--- a/box-drawing.c
+++ b/box-drawing.c
@@ -1303,8 +1303,8 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf)
assert(row_end > row_start);
assert(col_end > col_start);
- for (int r = max(row_start, 0); r < min(row_end, buf->height); r++) {
- for (int c = max(col_start, 0); c < min(col_end, buf->width); c++) {
+ for (int r = max(row_start, 0); r < max(min(row_end, buf->height), 0); r++) {
+ for (int c = max(col_start, 0); c < max(min(col_end, buf->width), 0); c++) {
size_t idx = c / 8;
size_t bit_no = c % 8;
buf->data[r * buf->stride + idx] |= 1 << bit_no;
@@ -1323,9 +1323,11 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf)
for (int y = 0; y < thick; y++) {
int row = (buf->height - thick) / 2 + y;
int col = buf->width - 1;
- size_t ofs = col / 8;
- size_t bit_no = col % 8;
- buf->data[row * buf->stride + ofs] |= 1 << bit_no;
+ if (row >= 0 && row < buf->height && col >= 0 && col < buf->width) {
+ size_t ofs = col / 8;
+ size_t bit_no = col % 8;
+ buf->data[row * buf->stride + ofs] |= 1 << bit_no;
+ }
}
}
@@ -1333,9 +1335,11 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf)
for (int x = 0; x < thick; x++) {
int row = buf->height - 1;
int col = (buf->width - thick) / 2 + x;
- size_t ofs = col / 8;
- size_t bit_no = col % 8;
- buf->data[row * buf->stride + ofs] |= 1 << bit_no;
+ if (row >= 0 && row < buf->height && col >= 0 && col < buf->width) {
+ size_t ofs = col / 8;
+ size_t bit_no = col % 8;
+ buf->data[row * buf->stride + ofs] |= 1 << bit_no;
+ }
}
}
}