]> granicus.if.org Git - graphviz/commitdiff
Fix line folding bug where previous fgets ends in '\\' and next
authorerg <devnull@localhost>
Thu, 12 Oct 2006 23:11:49 +0000 (23:11 +0000)
committererg <devnull@localhost>
Thu, 12 Oct 2006 23:11:49 +0000 (23:11 +0000)
fgets returns a single '\n'. The code needs to handle this case,
and back up the buffer appropriately.

lib/graph/lexer.c

index ffe734e79fab03a8f57a085ccf17294cf28f3951..f86afd1580fe4232253876cbef3c73e0e51ed33d 100644 (file)
@@ -249,12 +249,18 @@ static char *lex_gets(void)
                continue;
            }
            Line_number++;
-           if ((len > 1) && (clp[len - 2] == '\\')) {  /* escaped newline */
+               /* Note it is possible len == 1 and last character in
+                * previous read was '\\'
+                * It is also possible to have curlen=0, and read in
+                * "\\\n". 
+                */
+           if (clp[len - 2] == '\\') { /* escaped newline */
                len = len - 2;
                clp[len] = '\0';
            }
        }
        curlen += len;
+       /* the following test relies on having AG.linebuf[0] == '\0' */
     } while (clp[len - 1] != '\n');
 
     if (curlen > 0)