aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--box-drawing.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/box-drawing.c b/box-drawing.c
index 8584f8ad..07deb387 100644
--- a/box-drawing.c
+++ b/box-drawing.c
@@ -24,8 +24,11 @@ thickness(float pts, int dpi)
static void
_hline(uint8_t *buf, int x1, int x2, int y, int thick, int width, int height, int stride)
{
+ x1 = min(max(x1, 0), width);
+ x2 = min(max(x2, 0), width);
+
for (size_t row = max(y, 0); row < min(y + thick, height); row++) {
- for (size_t col = max(x1, 0); col < min(x2, width); col++) {
+ for (size_t col = x1; col < x2; col++) {
size_t idx = col / 8;
size_t bit_no = col % 8;
buf[row * stride + idx] |= 1 << bit_no;
@@ -38,7 +41,10 @@ _hline(uint8_t *buf, int x1, int x2, int y, int thick, int width, int height, in
static void
_vline(uint8_t *buf, int y1, int y2, int x, int thick, int width, int height, int stride)
{
- for (size_t row = max(y1, 0); row < min(y2, height); row++) {
+ y1 = min(max(y1, 0), height);
+ y2 = min(max(y2, 0), height);
+
+ for (size_t row = y1; row < y2; row++) {
for (size_t col = max(x, 0); col < min(x + thick, width); col++) {
size_t idx = col / 8;
size_t bit_no = col % 8;