From patchwork Thu Jun 1 14:27:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 70447 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 EE94A3857024 for ; Thu, 1 Jun 2023 14:28:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE94A3857024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685629709; bh=YWl/wmEMzlRwx3EA16KUhFiIy7H0yehy619JYMcmG4A=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ii0lDdiLFHjtuzyCsDapqx+A5Wu+5hMmFnc4qpMRVteIZ53Nb0MF5BWVH+1nBKGvr 7yLCpel452KFqsc8mrBXCxHmTXfm7yrVWtPdAcMwqSFLIhjGmizqXtDtUMuZEfJKE0 qy19mLNdbviu4MnCbpGMreP2q7wWUMJhsJtGZH+E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A5DB23858401 for ; Thu, 1 Jun 2023 14:28:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A5DB23858401 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-512-YXUvF4iGNe6I-wcPJZnk9w-1; Thu, 01 Jun 2023 10:28:03 -0400 X-MC-Unique: YXUvF4iGNe6I-wcPJZnk9w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D7C485A5BB; Thu, 1 Jun 2023 14:28:03 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 688A99E72; Thu, 1 Jun 2023 14:28:02 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v5 01/12] catgets/gencat.c: fix warn unused result Date: Thu, 1 Jun 2023 16:27:42 +0200 Message-Id: <20230601142747.104444-1-fberat@redhat.com> In-Reply-To: <20230418121130.844302-3-fberat@redhat.com> References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_B=C3=A9rat_via_Libc-alpha?= From: Frederic Berat Reply-To: =?utf-8?b?RnLDqWTDqXJpYyBCw6lyYXQ=?= Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in glibc. Reviewed-by: Siddhesh Poyarekar --- Changes since v4: - Mark strings for translation with gettext. - Fixed typo in (ret == 0) case catgets/gencat.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/catgets/gencat.c b/catgets/gencat.c index 61ac797349..826596c2e4 100644 --- a/catgets/gencat.c +++ b/catgets/gencat.c @@ -838,6 +838,26 @@ invalid character: message ignored")); return current; } +static void +write_all (int fd, const void *buffer, size_t length) +{ + const char *p = buffer; + const char *end = p + length; + while (p < end) + { + ssize_t ret = write (fd, p, end - p); + if (ret < 0) + error (EXIT_FAILURE, errno, + gettext ("write of %zu bytes failed after %td: %m"), + length, p - (const char *) buffer); + + if (ret == 0) + error (EXIT_FAILURE, 0, + gettext ("write returned 0 after writing %td bytes of %zu"), + p - (const char *) buffer, length); + p += ret; + } +} static void write_out (struct catalog *catalog, const char *output_name, @@ -927,12 +947,11 @@ write_out (struct catalog *catalog, const char *output_name, obj.plane_size = best_size; obj.plane_depth = best_depth; + uint32_t array_size = best_size * best_depth * sizeof (uint32_t) * 3; /* Allocate room for all needed arrays. */ - array1 = - (uint32_t *) alloca (best_size * best_depth * sizeof (uint32_t) * 3); - memset (array1, '\0', best_size * best_depth * sizeof (uint32_t) * 3); - array2 - = (uint32_t *) alloca (best_size * best_depth * sizeof (uint32_t) * 3); + array1 = (uint32_t *) alloca (array_size); + memset (array1, '\0', array_size); + array2 = (uint32_t *) alloca (array_size); obstack_init (&string_pool); set_run = catalog->all_sets; @@ -985,22 +1004,22 @@ write_out (struct catalog *catalog, const char *output_name, } /* Write out header. */ - write (fd, &obj, sizeof (obj)); + write_all(fd, &obj, sizeof (obj)); /* We always write out the little endian version of the index arrays. */ #if __BYTE_ORDER == __LITTLE_ENDIAN - write (fd, array1, best_size * best_depth * sizeof (uint32_t) * 3); - write (fd, array2, best_size * best_depth * sizeof (uint32_t) * 3); + write_all(fd, array1, array_size); + write_all(fd, array2, array_size); #elif __BYTE_ORDER == __BIG_ENDIAN - write (fd, array2, best_size * best_depth * sizeof (uint32_t) * 3); - write (fd, array1, best_size * best_depth * sizeof (uint32_t) * 3); + write_all(fd, array2, array_size); + write_all(fd, array1, array_size); #else # error Cannot handle __BYTE_ORDER byte order #endif /* Finally write the strings. */ - write (fd, strings, strings_size); + write_all(fd, strings, strings_size); if (fd != STDOUT_FILENO) close (fd);