applied cls' patch, thanks Connor! 8e3e6117
anselm@garbe.us · 2010-03-22 07:50 1 file(s) · +13 −11
dmenu.c +13 −11
372 372
373 373
void
374 374
kpress(XKeyEvent * e) {
375 -
	char buf[32];
375 +
	char buf[sizeof text];
376 376
	int i, num;
377 377
	unsigned int len;
378 378
	KeySym ksym;
457 457
				char *c;
458 458
				if(!(fp = (FILE*)popen("sselp", "r")))
459 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 461
				pclose(fp);
462 462
				if(c == NULL)
463 463
					return;
464 464
			}
465 -
			len = strlen(text);
466 -
			if(len && text[len-1] == '\n')
467 -
				text[--len] = '\0';
468 -
			match(text);
469 -
			drawmenu();
470 -
			return;
465 +
			num = strlen(buf);
466 +
			if(num && buf[num-1] == '\n')
467 +
				buf[--num] = '\0';
468 +
			break;
471 469
		}
472 470
	}
473 471
	switch(ksym) {
474 472
	default:
473 +
		num = MIN(num, sizeof text - cursor);
475 474
		if(num && !iscntrl((int) buf[0])) {
476 -
			buf[num] = 0;
477 -
			memmove(text + cursor + num, text + cursor, sizeof text - cursor);
478 -
			strncpy(text + cursor, buf, sizeof text - cursor);
475 +
			memmove(text + cursor + num, text + cursor, sizeof text - cursor - num);
476 +
			memmove(text + cursor, buf, num);
479 477
			cursor+=num;
480 478
			match(text);
481 479
		}
486 484
			cursor--;
487 485
			match(text);
488 486
		}
487 +
		break;
488 +
	case XK_Delete:
489 +
		memmove(text + cursor, text + cursor + 1, sizeof text - cursor);
490 +
		match(text);
489 491
		break;
490 492
	case XK_End:
491 493
		if(!item)