accept NULs in is_control_egc(), fixing notcurses-input

This commit is contained in:
nick black 2021-06-27 07:52:33 -04:00
parent 490c89f694
commit 6ba67a6f21
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 5 additions and 5 deletions

View File

@ -1201,7 +1201,6 @@ namespace ncpp
return nccell_extract (plane, cell, stylemask, channels);
}
// FIXME these can except if fed a sprixel, right (returns NULL)?
const char* get_extended_gcluster (Cell &cell) const noexcept
{
return nccell_extended_gcluster (plane, cell);

View File

@ -1474,11 +1474,12 @@ plane_blit_sixel(sprixel* spx, char* s, int bytes, int leny, int lenx,
return 0;
}
// is it a control character? check C0 and C1, but don't count empty strings.
// is it a control character? check C0 and C1, but don't count empty strings,
// nor single-byte strings containing only a NUL character.
static inline bool
is_control_egc(const unsigned char* egc, int bytes){
if(bytes == 1){
if(iscntrl(*egc)){
if(*egc && iscntrl(*egc)){
return true;
}
}else if(bytes == 2){

View File

@ -1547,13 +1547,13 @@ ncplane_put(ncplane* n, int y, int x, const char* egc, int cols,
return -1;
}
// reject any control character for output other than newline (and then only
// on a scrolling plane). this also rejects any 0-length EGC.
// on a scrolling plane).
if(*egc == '\n'){
if(!n->scrolling){
logerror("Rejecting newline on non-scrolling plane\n");
return -1;
}
}else if(bytes == 0 || is_control_egc((const unsigned char*)egc, bytes)){
}else if(is_control_egc((const unsigned char*)egc, bytes)){
logerror("Rejecting %dB control character\n", bytes);
return -1;
}