Skip to content

Commit 401e15b

Browse files
committed
Fix access violation when function coverage is disabled. See #311
Signed-off-by: Henry Cox <[email protected]>
1 parent 2de737a commit 401e15b

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

bin/genhtml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5615,19 +5615,22 @@ sub _synthesize
56155615
$last_line = $l if ('<' ne substr($l, 0, 1) && $l > $last_line);
56165616
}
56175617
my %functionDecls;
5618-
while (my ($fnName, $funcEntry) = each(%{$fileCovInfo->functionMap()})) {
5619-
my $line = $funcEntry->line();
5620-
my $end = $funcEntry->end_line();
5621-
$last_line = $line if $line > $last_line;
5622-
$functionDecls{$line} = "/* BEGIN: function \"$fnName\" */"
5623-
if ($line >= $currentLast);
5624-
if (defined($end)) {
5625-
$functionDecls{$end} = "/* END: function \"$fnName\" */"
5626-
if ($end >= $currentLast);
5627-
if ($end > $last_line) {
5628-
# function end is not an executable line,
5629-
# but is after last executable line
5630-
$last_line = $end;
5618+
if ($lcovutil::func_coverage) {
5619+
while (my ($fnName, $funcEntry) = each(%{$fileCovInfo->functionMap()}))
5620+
{
5621+
my $line = $funcEntry->line();
5622+
my $end = $funcEntry->end_line();
5623+
$last_line = $line if $line > $last_line;
5624+
$functionDecls{$line} = "/* BEGIN: function \"$fnName\" */"
5625+
if ($line >= $currentLast);
5626+
if (defined($end)) {
5627+
$functionDecls{$end} = "/* END: function \"$fnName\" */"
5628+
if ($end >= $currentLast);
5629+
if ($end > $last_line) {
5630+
# function end is not an executable line,
5631+
# but is after last executable line
5632+
$last_line = $end;
5633+
}
56315634
}
56325635
}
56335636
}
@@ -13170,7 +13173,7 @@ sub write_file_table(*$$$$$$)
1317013173
[ $suppressedSecondaryHeader,
1317113174
'<sup>&lowast;&lowast;</sup> Bin \'Total\' header elided when bin contains only one entry.'
1317213175
],
13173-
[ !$includeFunctionColumns,
13176+
[ $lcovutil::func_coverage && !$includeFunctionColumns,
1317413177
"Note: 'Function Coverage' columns elided as function owner is not identified."
1317513178
]
1317613179
) {

tests/gendiffcov/synthesize/synthesize.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ LCOV_OPTS="$EXTRA_GCOV_OPTS --branch-coverage $PARALLEL $PROFILE"
105105
DIFFCOV_OPTS="--function-coverage --branch-coverage --demangle-cpp --frame --prefix $PARENT $PROFILE $PARALLEL"
106106

107107
rm -f *.cpp *.gcno *.gcda a.out *.info *.log *.json dumper* *.annotated annotate.sh
108-
rm -rf ./vanilla ./annotated ./annotateErr ./annotated2 ./annotateErr2 ./range ./filter ./cover_db
108+
rm -rf ./vanilla ./annotated ./annotateErr ./annotated2 ./annotateErr2 ./range ./filter ./cover_db annotated_nofunc
109109

110110
if [ "x$COVER" != 'x' ] && [ 0 != $LOCAL_COVERAGE ] ; then
111111
cover -delete
@@ -180,7 +180,33 @@ if [ 0 != ${PIPESTATUS[0]} ] ; then
180180
exit 1
181181
fi
182182
fi
183+
# expect to see generated function labels
184+
for label in 'BEGIN' 'END' ; do
185+
grep -E "$label: function .+outOfRangeFnc" annotated/synthesize/test.cpp.gcov.html
186+
if [ 0 != $? ] ; then
187+
echo "ERROR: genhtml didn't generate function $label label"
188+
if [ 0 == $KEEP_GOING ] ; then
189+
exit 1
190+
fi
191+
fi
192+
done
183193
194+
echo genhtml $DIFFCOV_OPTS --annotate-script `pwd`/annotate.sh --show-owners all -o annotated_nofunc --no-function-coverage --ignore range ./munged.info
195+
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --annotate-script `pwd`/annotate.sh --show-owners all -o annotated_nofunc --no-function-coverage ./munged.info --ignore range 2>&1 | tee annotate.log
196+
if [ 0 != ${PIPESTATUS[0]} ] ; then
197+
echo "ERROR: genhtml annotated_nofunc failed"
198+
if [ 0 == $KEEP_GOING ] ; then
199+
exit 1
200+
fi
201+
fi
202+
# should not be generated..
203+
grep -E "function .+outOfRangeFnc" annotated_nofunc/synthesize/test.cpp.gcov.html
204+
if [ 0 == $? ] ; then
205+
echo "ERROR: genhtml should not have generated function label"
206+
if [ 0 == $KEEP_GOING ] ; then
207+
exit 1
208+
fi
209+
fi
184210
185211
echo genhtml $DIFFCOV_OPTS -o vanilla --ignore range ./munged.info
186212
$COVER $GENHTML_TOOL $DIFFCOV_OPTS -o vanilla --ignore range ./munged.info 2>&1 | tee vanilla.log

0 commit comments

Comments
 (0)