From e6bc09084c2aad014bbcbf065616ae0801edea8d Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 17 Oct 2020 15:58:30 -0400 Subject: [PATCH] notcurses_align: return error on negative column count --- include/notcurses/notcurses.h | 6 ++++++ tests/fade.cpp | 2 ++ 2 files changed, 8 insertions(+) diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index b9c3968b0..3ec0a1803 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1300,6 +1300,9 @@ API void ncplane_center_abs(const struct ncplane* n, int* RESTRICT y, // requirements of 'align'. static inline int notcurses_align(int availcols, ncalign_e align, int cols){ + if(cols < 0){ + return -INT_MAX; + } if(align == NCALIGN_LEFT){ return 0; } @@ -1488,6 +1491,9 @@ ncplane_putwstr_aligned(struct ncplane* n, int y, ncalign_e align, const wchar_t* gclustarr){ int width = wcswidth(gclustarr, INT_MAX); int xpos = ncplane_align(n, align, width); + if(xpos < 0){ + return -1; + } return ncplane_putwstr_yx(n, y, xpos, gclustarr); } diff --git a/tests/fade.cpp b/tests/fade.cpp index 59376a3df..bb5a10a07 100644 --- a/tests/fade.cpp +++ b/tests/fade.cpp @@ -94,7 +94,9 @@ TEST_CASE("Fade") { ts.tv_nsec = 75000000; ncplane_erase(n_); ncplane_set_fg_rgb(n_, 0xffd700); + CHECK(0 < ncplane_printf_aligned(n_, dimy - 1, NCALIGN_LEFT, "pulllllllse")); CHECK(0 < ncplane_printf_aligned(n_, dimy - 1, NCALIGN_CENTER, "pulllllllse")); + CHECK(0 < ncplane_printf_aligned(n_, dimy - 1, NCALIGN_RIGHT, "pulllllllse")); struct timespec pulsestart; clock_gettime(CLOCK_MONOTONIC, &pulsestart); CHECK(0 < ncplane_pulse(n_, &ts, pulser, &pulsestart));