Do not trust isalpha(c) for values > 255.

Fixes #174.
This commit is contained in:
Hisham Muhammad 2015-03-22 22:56:28 -03:00
parent 1e0c530a46
commit 442a0d33e4
7 changed files with 7 additions and 7 deletions

View File

@ -55,7 +55,7 @@ static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
} }
default: default:
{ {
if (isalpha(ch)) if (ch < 255 && isalpha(ch))
result = Panel_selectByTyping(super, ch); result = Panel_selectByTyping(super, ch);
break; break;
} }

View File

@ -102,7 +102,7 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
break; break;
} }
default: default:
if (isalpha(ch)) if (ch < 255 && isalpha(ch))
result = Panel_selectByTyping(super, ch); result = Panel_selectByTyping(super, ch);
if (result == BREAK_LOOP) if (result == BREAK_LOOP)
result = IGNORED; result = IGNORED;

View File

@ -70,7 +70,7 @@ static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
} }
default: default:
{ {
if (isalpha(ch)) if (ch < 255 && isalpha(ch))
result = Panel_selectByTyping(super, ch); result = Panel_selectByTyping(super, ch);
if (result == BREAK_LOOP) if (result == BREAK_LOOP)
result = IGNORED; result = IGNORED;

View File

@ -153,7 +153,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
} }
} }
doSearch = false; doSearch = false;
} else if (isprint((char)ch) && (mode->index < INCMODE_MAX)) { } else if (ch < 255 && isprint((char)ch) && (mode->index < INCMODE_MAX)) {
mode->buffer[mode->index] = ch; mode->buffer[mode->index] = ch;
mode->index++; mode->index++;
mode->buffer[mode->index] = 0; mode->buffer[mode->index] = 0;

View File

@ -427,7 +427,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
if (!this->eventHandlerBuffer) if (!this->eventHandlerBuffer)
this->eventHandlerBuffer = calloc(100, 1); this->eventHandlerBuffer = calloc(100, 1);
if (isalnum(ch)) { if (ch < 255 && isalnum(ch)) {
int len = strlen(this->eventHandlerBuffer); int len = strlen(this->eventHandlerBuffer);
if (len < 99) { if (len < 99) {
this->eventHandlerBuffer[len] = ch; this->eventHandlerBuffer[len] = ch;

View File

@ -128,7 +128,7 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
int newLen = from + len; int newLen = from + len;
RichString_setLen(this, newLen); RichString_setLen(this, newLen);
for (int i = from, j = 0; i < newLen; i++, j++) for (int i = from, j = 0; i < newLen; i++, j++)
this->chptr[i] = (isprint(data_c[j]) ? data_c[j] : '?') | attrs; this->chptr[i] = (data_c[j] >= 32 ? data_c[j] : '?') | attrs;
this->chptr[newLen] = 0; this->chptr[newLen] = 0;
} }

2
htop.c
View File

@ -852,7 +852,7 @@ int main(int argc, char** argv) {
continue; continue;
} }
if (isdigit((char)ch)) { if (ch < 255 && isdigit((char)ch)) {
if (Panel_size(panel) == 0) continue; if (Panel_size(panel) == 0) continue;
pid_t pid = ch-48 + acc; pid_t pid = ch-48 + acc;
for (int i = 0; i < ProcessList_size(pl); i++) { for (int i = 0; i < ProcessList_size(pl); i++) {