public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Sebastian Huber <sh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-18] gcov: Record EOF error during read
Date: Thu, 28 Apr 2022 19:41:59 +0000 (GMT)	[thread overview]
Message-ID: <20220428194159.2ADC4385742B@sourceware.org> (raw)

https://gcc.gnu.org/g:ef9a53feae5701953da9161afef2aea0329ec8b2

commit r13-18-gef9a53feae5701953da9161afef2aea0329ec8b2
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date:   Thu Mar 31 10:10:02 2022 +0200

    gcov: Record EOF error during read
    
    Use an enum for file error codes.
    
    gcc/
    
            * gcov-io.cc (gcov_file_error): New enum.
            (gcov_var): Use gcov_file_error enum for the error member.
            (gcov_open): Use GCOV_FILE_NO_ERROR.
            (gcov_close): Use GCOV_FILE_WRITE_ERROR.
            (gcov_write): Likewise.
            (gcov_write_unsigned): Likewise.
            (gcov_write_string): Likewise.
            (gcov_read_bytes): Set error code if EOF is reached.
            (gcov_read_counter): Use GCOV_FILE_COUNTER_OVERFLOW.

Diff:
---
 gcc/gcov-io.cc | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/gcc/gcov-io.cc b/gcc/gcov-io.cc
index 7e1fb10b612..fdf745e6ce1 100644
--- a/gcc/gcov-io.cc
+++ b/gcc/gcov-io.cc
@@ -29,10 +29,20 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 static gcov_unsigned_t *gcov_read_words (void *buffer, unsigned);
 
+/* Indicates the last gcov file access error or that no error occurred
+   so far.  */
+enum gcov_file_error
+{
+  GCOV_FILE_COUNTER_OVERFLOW = -1,
+  GCOV_FILE_NO_ERROR = 0,
+  GCOV_FILE_WRITE_ERROR = 1,
+  GCOV_FILE_EOF = 2
+};
+
 struct gcov_var
 {
   FILE *file;
-  int error;			/* < 0 overflow, > 0 disk error.  */
+  enum gcov_file_error error;
   int mode;			/* < 0 writing, > 0 reading.  */
   int endian;			/* Swap endianness.  */
 #ifdef IN_GCOV_TOOL
@@ -113,7 +123,7 @@ gcov_open (const char *name, int mode)
 #endif
 
   gcov_nonruntime_assert (!gcov_var.file);
-  gcov_var.error = 0;
+  gcov_var.error = GCOV_FILE_NO_ERROR;
 #if !IN_LIBGCOV || defined (IN_GCOV_TOOL)
   gcov_var.endian = 0;
 #endif
@@ -217,7 +227,7 @@ gcov_close (void)
   if (gcov_var.file)
     {
       if (fclose (gcov_var.file))
-	gcov_var.error = 1;
+	gcov_var.error = GCOV_FILE_WRITE_ERROR;
 
       gcov_var.file = 0;
     }
@@ -253,7 +263,7 @@ gcov_write (const void *data, unsigned length)
 {
   gcov_unsigned_t r = fwrite (data, length, 1, gcov_var.file);
   if (r != 1)
-    gcov_var.error = 1;
+    gcov_var.error = GCOV_FILE_WRITE_ERROR;
 }
 
 /* Write unsigned VALUE to coverage file.  */
@@ -263,7 +273,7 @@ gcov_write_unsigned (gcov_unsigned_t value)
 {
   gcov_unsigned_t r = fwrite (&value, sizeof (value), 1, gcov_var.file);
   if (r != 1)
-    gcov_var.error = 1;
+    gcov_var.error = GCOV_FILE_WRITE_ERROR;
 }
 
 #if !IN_LIBGCOV
@@ -283,7 +293,7 @@ gcov_write_string (const char *string)
     {
       gcov_unsigned_t r = fwrite (string, length, 1, gcov_var.file);
       if (r != 1)
-	gcov_var.error = 1;
+	gcov_var.error = GCOV_FILE_WRITE_ERROR;
     }
 }
 #endif
@@ -385,7 +395,11 @@ gcov_read_bytes (void *buffer, unsigned count)
 
   unsigned read = fread (buffer, count, 1, gcov_var.file);
   if (read != 1)
-    return NULL;
+    {
+      if (feof (gcov_var.file))
+	gcov_var.error = GCOV_FILE_EOF;
+      return NULL;
+    }
 
 #ifdef IN_GCOV_TOOL
   gcov_var.pos += count;
@@ -434,7 +448,7 @@ gcov_read_counter (void)
   if (sizeof (value) > sizeof (gcov_unsigned_t))
     value |= ((gcov_type) from_file (buffer[1])) << 32;
   else if (buffer[1])
-    gcov_var.error = -1;
+    gcov_var.error = GCOV_FILE_COUNTER_OVERFLOW;
 
   return value;
 }


                 reply	other threads:[~2022-04-28 19:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220428194159.2ADC4385742B@sourceware.org \
    --to=sh@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).