From patchwork Fri Apr 28 12:21:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68471 X-Patchwork-Delegate: siddhesh@gotplt.org 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 20BD43851C3E for ; Fri, 28 Apr 2023 12:36:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20BD43851C3E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685397; bh=SsAu+nFhZ7BNYzhp3FfZTmoPOP8TnWGCY9pJOc/0mYQ=; 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=Msk92w2Tl7rfebH5yl6UCrpwcElE9CbI+uOisyG2ZR185sd47pY4Jcl3pHxs0l5U1 nmrK8Ng2vkDkmHzrXoAki2eV2vTh0tnTfkswjwrIzoYHETJRDC4nM9yiRLiyQG2Ssu 3XzacC90nxPR55fgJAvUbECaeXYrAy9yXf8Zuct8= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id C283C3858C60 for ; Fri, 28 Apr 2023 12:35:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C283C3858C60 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-191-dATgR5jvOtuzifC5q0mCqQ-1; Fri, 28 Apr 2023 08:35:23 -0400 X-MC-Unique: dATgR5jvOtuzifC5q0mCqQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1AA083822DEA; Fri, 28 Apr 2023 12:35:22 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73A14C15BA0; Fri, 28 Apr 2023 12:35:21 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 01/15] catgets/gencat.c: fix warn unused result Date: Fri, 28 Apr 2023 14:21:28 +0200 Message-Id: <20230428122142.928135-2-fberat@redhat.com> In-Reply-To: <20230418121130.844302-3-fberat@redhat.com> References: <20230428122142.928135-1-fberat@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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, RCVD_IN_MSPIKE_H2, 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. --- catgets/gencat.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/catgets/gencat.c b/catgets/gencat.c index 61ac797349..ceaec67011 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, + "write of %zu bytes failed after %td: %m", + length, p - (const char *) buffer); + + if (ret == 0) + error (EXIT_FAILURE, 0, + "write return 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);