From 3a60b19514705f7f61908fd727d2e69565ee1947 Mon Sep 17 00:00:00 2001 From: Connor Lane Smith Date: Mon, 16 May 2011 23:35:14 +0100 Subject: fix possible overflow --- dmenu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'dmenu.c') diff --git a/dmenu.c b/dmenu.c index a32131c..c4b7908 100644 --- a/dmenu.c +++ b/dmenu.c @@ -31,7 +31,7 @@ static void grabkeyboard(void); static void insert(const char *str, ssize_t n); static void keypress(XKeyEvent *ev); static void match(Bool sub); -static size_t nextrune(int incr); +static size_t nextrune(int inc); static void paste(void); static void readstdin(void); static void run(void); @@ -426,10 +426,10 @@ match(Bool sub) { } size_t -nextrune(int incr) { - size_t n, len = strlen(text); +nextrune(int inc) { + ssize_t n; - for(n = cursor + incr; n < len && (text[n] & 0xc0) == 0x80; n += incr); + for(n = cursor + inc; n + inc >= 0 && (text[n] & 0xc0) == 0x80; n += inc); return n; } -- cgit v1.2.3-13-gbd6f