]> git.wh0rd.org Git - nano.git/commitdiff
fix potential infinite loop in mbrevstrpbrk()
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Thu, 2 Feb 2006 22:30:40 +0000 (22:30 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Thu, 2 Feb 2006 22:30:40 +0000 (22:30 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3270 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

src/chars.c

index bfdaaf62ec43d0e73ca4e0921cdb0276ad6a330d..41eaa11fb60dc30b0401e642c63d3a86a9aeaf17 100644 (file)
@@ -910,14 +910,19 @@ char *mbrevstrpbrk(const char *s, const char *accept, const char
 
 #ifdef ENABLE_UTF8
     if (ISSET(USE_UTF8)) {
-       while (rev_start >= s) {
+       bool begin_line = FALSE;
+
+       while (!begin_line) {
            const char *q = (*rev_start == '\0') ? NULL :
                mbstrchr(accept, rev_start);
 
            if (q != NULL)
                return (char *)rev_start;
 
-           rev_start = s + move_mbleft(s, rev_start - s);
+           if (rev_start == s)
+               begin_line = TRUE;
+           else
+               rev_start = s + move_mbleft(s, rev_start - s);
        }
 
        return NULL;