notcurses_align: return error on negative column count

This commit is contained in:
nick black 2020-10-17 15:58:30 -04:00
parent df8ee463c4
commit e6bc09084c
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 8 additions and 0 deletions

View File

@ -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);
}

View File

@ -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));