aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmenu.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/dmenu.c b/dmenu.c
index aef8ae5..5f16894 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -372,7 +372,7 @@ initfont(const char *fontstr) {
372 372
373void 373void
374kpress(XKeyEvent * e) { 374kpress(XKeyEvent * e) {
375 char buf[32]; 375 char buf[sizeof text];
376 int i, num; 376 int i, num;
377 unsigned int len; 377 unsigned int len;
378 KeySym ksym; 378 KeySym ksym;
@@ -457,25 +457,23 @@ kpress(XKeyEvent * e) {
457 char *c; 457 char *c;
458 if(!(fp = (FILE*)popen("sselp", "r"))) 458 if(!(fp = (FILE*)popen("sselp", "r")))
459 eprint("dmenu: Could not popen sselp\n"); 459 eprint("dmenu: Could not popen sselp\n");
460 c = fgets(text + len, sizeof(text) - len, fp); 460 c = fgets(buf, sizeof buf, fp);
461 pclose(fp); 461 pclose(fp);
462 if(c == NULL) 462 if(c == NULL)
463 return; 463 return;
464 } 464 }
465 len = strlen(text); 465 num = strlen(buf);
466 if(len && text[len-1] == '\n') 466 if(num && buf[num-1] == '\n')
467 text[--len] = '\0'; 467 buf[--num] = '\0';
468 match(text); 468 break;
469 drawmenu();
470 return;
471 } 469 }
472 } 470 }
473 switch(ksym) { 471 switch(ksym) {
474 default: 472 default:
473 num = MIN(num, sizeof text - cursor);
475 if(num && !iscntrl((int) buf[0])) { 474 if(num && !iscntrl((int) buf[0])) {
476 buf[num] = 0; 475 memmove(text + cursor + num, text + cursor, sizeof text - cursor - num);
477 memmove(text + cursor + num, text + cursor, sizeof text - cursor); 476 memmove(text + cursor, buf, num);
478 strncpy(text + cursor, buf, sizeof text - cursor);
479 cursor+=num; 477 cursor+=num;
480 match(text); 478 match(text);
481 } 479 }
@@ -487,6 +485,10 @@ kpress(XKeyEvent * e) {
487 match(text); 485 match(text);
488 } 486 }
489 break; 487 break;
488 case XK_Delete:
489 memmove(text + cursor, text + cursor + 1, sizeof text - cursor);
490 match(text);
491 break;
490 case XK_End: 492 case XK_End:
491 if(!item) 493 if(!item)
492 return; 494 return;