diff: fix infinite loop with --color-moved --ignore-space-change
[gitweb.git] / diff.c
diff --git a/diff.c b/diff.c
index 0c604726c06b07c2cd17bbdf05dc669ae92e5ae4..af9b9528861f4dd1ea901b5c9bc897e335cf2cb1 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -720,20 +720,22 @@ static int next_byte(const char **cp, const char **endp,
        if (*cp > *endp)
                return -1;
 
-       if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_CHANGE)) {
-               while (*cp < *endp && isspace(**cp))
-                       (*cp)++;
-               /*
-                * After skipping a couple of whitespaces, we still have to
-                * account for one space.
-                */
-               return (int)' ';
-       }
+       if (isspace(**cp)) {
+               if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE_CHANGE)) {
+                       while (*cp < *endp && isspace(**cp))
+                               (*cp)++;
+                       /*
+                        * After skipping a couple of whitespaces,
+                        * we still have to account for one space.
+                        */
+                       return (int)' ';
+               }
 
-       if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
-               while (*cp < *endp && isspace(**cp))
-                       (*cp)++;
-               /* return the first non-ws character via the usual below */
+               if (DIFF_XDL_TST(diffopt, IGNORE_WHITESPACE)) {
+                       while (*cp < *endp && isspace(**cp))
+                               (*cp)++;
+                       /* return the first non-ws character via the usual below */
+               }
        }
 
        retval = (unsigned char)(**cp);