From ec6915157c741c96bfeed5a2a58246d59ccefdb5 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 17 Mar 2012 21:16:03 +0100 Subject: [PATCH] Improve line continuation to handle ignored lines correctly. --- bin/blhc | 28 ++++++++++++++++++++-------- t/logs/bad-multiline | 10 ++++++++++ t/tests.t | 5 +++-- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/bin/blhc b/bin/blhc index 38ca653..d8c621b 100755 --- a/bin/blhc +++ b/bin/blhc @@ -266,6 +266,7 @@ my @input = (); my $start = 0; my $continuation = 0; +my $complete_line = undef; while (my $line = <>) { # We skip over unimportant lines at the beginning to prevent false # positives. @@ -297,10 +298,26 @@ while (my $line = <>) { # Join lines, but leave the "\" in place so it's clear where the # original line break was. - chomp $input[-1]; - $input[-1] .= ' ' . $line; + chomp $complete_line; + $complete_line .= ' ' . $line; + } + # Line continuation, line ends with "\". + if ($line =~ /\\\s*$/) { + $continuation = 1; + # Start line continuation. + if (not defined $complete_line) { + $complete_line = $line; + } + next; + } + + if (not $continuation) { + # Use the complete line if a line continuation occurred. + if (defined $complete_line) { + $line = $complete_line; + $complete_line = undef; + } - } else { # Ignore lines with no compiler commands. next if $line !~ /\b$cc_regex(?:\s|\\)/ and not $non_verbose; @@ -311,11 +328,6 @@ while (my $line = <>) { push @input, $line; } - - # Line continuation, line ends with "\". - if ($line =~ /\\\s*$/) { - $continuation = 1; - } } } diff --git a/t/logs/bad-multiline b/t/logs/bad-multiline index 91f63a6..ff7a826 100644 --- a/t/logs/bad-multiline +++ b/t/logs/bad-multiline @@ -30,3 +30,13 @@ gcc -g -O2 --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-s gcc -D_FORTIFY_SOURCE=2 -fstack-protector -c test-b.c # Escaped ";" - not really useful, just to check it works. gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security \; -Werror=format-security -D_FORTIFY_SOURCE=1 -c test-a.c + + +if ./bin-aux/missing --run makeinfo \ + test.texi > test.info; \ +then \ + echo good; \ +else + echo bad; \ +fi; \ +gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=1 -c test-b.c diff --git a/t/tests.t b/t/tests.t index 2a519a9..387ac2e 100644 --- a/t/tests.t +++ b/t/tests.t @@ -281,11 +281,12 @@ CFLAGS missing (-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat): g CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -Wformat-security -Werror=format-security -c test-b.c CFLAGS missing (-O2): gcc -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -c test-a.c CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -c test-a.c -CFLAGS missing (-g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -O2 -D_FORTIFY_SOURCE=2 -c test-b.c +CFLAGS missing (-g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): \ gcc -O2 -D_FORTIFY_SOURCE=2 -c test-b.c CFLAGS missing (-fstack-protector): gcc -g -O2 --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -c test-a.c CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -c test-a.c -CFLAGS missing (-g -O2 --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): gcc -D_FORTIFY_SOURCE=2 -fstack-protector -c test-b.c +CFLAGS missing (-g -O2 --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security): \ gcc -D_FORTIFY_SOURCE=2 -fstack-protector -c test-b.c CPPFLAGS missing (-D_FORTIFY_SOURCE=2): gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security \; -Werror=format-security -D_FORTIFY_SOURCE=1 -c test-a.c +CPPFLAGS missing (-D_FORTIFY_SOURCE=2): \ gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=1 -c test-b.c '; is_blhc 'bad-library', '--all', 8, -- 2.45.2