From: erg Date: Thu, 12 Oct 2006 23:11:49 +0000 (+0000) Subject: Fix line folding bug where previous fgets ends in '\\' and next X-Git-Tag: LAST_LIBGRAPH~32^2~5830 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c319a93f35cb5a66bf4a3469b18a99c1c11b4bef;p=graphviz Fix line folding bug where previous fgets ends in '\\' and next fgets returns a single '\n'. The code needs to handle this case, and back up the buffer appropriately. --- diff --git a/lib/graph/lexer.c b/lib/graph/lexer.c index ffe734e79..f86afd158 100644 --- a/lib/graph/lexer.c +++ b/lib/graph/lexer.c @@ -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)