From patchwork Thu Mar 31 11:35:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Huber X-Patchwork-Id: 52511 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3AF373864842 for ; Thu, 31 Mar 2022 11:40:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 50BA8383800C for ; Thu, 31 Mar 2022 11:35:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 50BA8383800C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nZt5O-000OQD-79; Thu, 31 Mar 2022 13:35:30 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZt5G-000Fo8-3Y; Thu, 31 Mar 2022 13:35:22 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id C5A104800B1; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id McKAjmNtCkbM; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 797D5480113; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Wvz3xDlvZoTE; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 45B60480124; Thu, 31 Mar 2022 13:35:21 +0200 (CEST) From: Sebastian Huber To: gcc-patches@gcc.gnu.org Subject: [RFC/gcov 11/12] gcov: Record EOF error during read Date: Thu, 31 Mar 2022 13:35:14 +0200 Message-Id: <20220331113515.35764-12-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> References: <20220331113515.35764-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26498/Thu Mar 31 10:19:05 2022) X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. --- gcc/gcov-io.cc | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/gcc/gcov-io.cc b/gcc/gcov-io.cc index 177f81166a6..60c762bf3a3 100644 --- a/gcc/gcov-io.cc +++ b/gcc/gcov-io.cc @@ -29,10 +29,17 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see static gcov_unsigned_t *gcov_read_words (void *buffer, unsigned); +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 +120,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 +224,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 +260,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 +270,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 +290,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 +392,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 +445,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; }