diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2022-02-03 21:17:10 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2022-02-04 17:15:35 +0000 |
| commit | e97e873b9ef448aa2796667ba1d0a69ffe2e07e0 (patch) | |
| tree | f493d55e41fa8f26dcf80cb931bef8753a122fff | |
| parent | Merge branch 'sixel-repeat-edge-cases' (diff) | |
box-drawing: LIGHT ARC: check for sqrt() failures
Closes #914
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | box-drawing.c | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e0196a8..f9ea4980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -123,6 +123,8 @@ * Sixel: large image resizes (triggered by e.g. large repeat counts in `DECGRI`) are now truncated instead of ignored. * Sixel: a repeat count of 0 in `DECGRI` now emits a single sixel. +* LIGHT ARC box drawing characters incorrectly rendered + platforms (https://codeberg.org/dnkl/foot/issues/914). ### Security diff --git a/box-drawing.c b/box-drawing.c index 3f8a38ef..09f16d6a 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1,6 +1,8 @@ #include "box-drawing.h" #include <stdio.h> +#include <math.h> +#include <fenv.h> #include <errno.h> #define LOG_MODULE "box-drawing" @@ -1282,9 +1284,19 @@ draw_box_drawings_light_arc(struct buf *buf, wchar_t wc) const int num_samples = height * 16; for (int i = 0; i < num_samples; i++) { + errno = 0; + feclearexcept(FE_ALL_EXCEPT); + double y = i / 16.; double x = sqrt(a2 * (1. - y * y / b2)); + /* See math_error(7) */ + if (errno != 0 || + fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW)) + { + continue; + } + const int row = round(y); const int col = round(x); |
