From 9067a1545085e360c8eb1c95a1b1a4480d9ee0b3 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 23 Oct 2020 16:20:53 +0200 Subject: [PATCH] gcov: fix reading of zero sections. I noticed that during coverage build of binutils. gcc/ChangeLog: * gcov.c (read_count_file): Never call gcov_sync with a negative value. --- gcc/gcov.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gcc/gcov.c b/gcc/gcov.c index b302e21..36938bd 100644 --- a/gcc/gcov.c +++ b/gcc/gcov.c @@ -1940,6 +1940,7 @@ read_count_file (void) while ((tag = gcov_read_unsigned ())) { unsigned length = gcov_read_unsigned (); + int read_length = (int)length; unsigned long base = gcov_position (); if (tag == GCOV_TAG_OBJECT_SUMMARY) @@ -1972,7 +1973,6 @@ read_count_file (void) } else if (tag == GCOV_TAG_FOR_COUNTER (GCOV_COUNTER_ARCS) && fn) { - int read_length = (int)length; length = abs (read_length); if (length != GCOV_TAG_COUNTER_LENGTH (fn->counts.size ())) goto mismatch; @@ -1980,10 +1980,10 @@ read_count_file (void) if (read_length > 0) for (ix = 0; ix != fn->counts.size (); ix++) fn->counts[ix] += gcov_read_counter (); - else - length = 0; } - gcov_sync (base, length); + if (read_length < 0) + read_length = 0; + gcov_sync (base, read_length); if ((error = gcov_is_error ())) { fnotice (stderr, -- 2.7.4