diff mbox series

[pushed] gcov: fix reading of zero sections.

Message ID bd11f2ae-acda-316d-57a9-0f19efd007a1@suse.cz
State New
Headers show
Series [pushed] gcov: fix reading of zero sections. | expand

Commit Message

Martin Liška Oct. 23, 2020, 2:22 p.m. UTC
I noticed that during coverage build of binutils.

gcc/ChangeLog:

	* gcov.c (read_count_file): Never call gcov_sync with a negative
	value.

Patch survives gcov.exp tests and I'm going to install it.

Martin

---
  gcc/gcov.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/gcc/gcov.c b/gcc/gcov.c
index b302e2197dd..36938bd0fce 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,