From ee28e6d7c817a920b29059e8c82fc43b879d7eba Mon Sep 17 00:00:00 2001 From: "David A. Wheeler" Date: Mon, 2 Sep 2013 18:37:08 -0400 Subject: Fix bug in ml_count.c [from: a_m0d] - "This patch fixes a bug with string handling in ml_count.c. The bug occurs with escaped string characters - when a file contains a quoted string character ('\"') then ml_count will crash with the message ml_count ERROR - terminated in string in ~/workspace/sloccount/trunk/../../basic//src/lexer.mll This patch fixes this by ensuring that escaped quotation marks do not mark the start of a string. - See https://sourceforge.net/p/sloccount/patches/15/ --- ml_count.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ml_count.c') diff --git a/ml_count.c b/ml_count.c index dc18f35..07cf39c 100644 --- a/ml_count.c +++ b/ml_count.c @@ -104,7 +104,9 @@ long sloc_count(char *filename, FILE *stream) { case '\\': /* Ignore next character if in string. But don't ignore newlines. */ - if (in_string && !ispeek('\n', stream)) + /* Also, eat a " character if it is escaped, so that we don't enter + * or exit a string */ + if ((in_string && !ispeek('\n', stream)) || ispeek('\"', stream)) getachar(stream); break; -- cgit v1.2.1