From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685629685; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YWl/wmEMzlRwx3EA16KUhFiIy7H0yehy619JYMcmG4A=; b=auRqt+uKzbnrWgs0uun/rdOyGTKYWZgS6xPEOUsuC0f9JszWNInJtSsmqL802yX+yCz3O5 OeSMDidl9rOwsPSHYkrVbvRsQciFCtssqSo6GYgQzjm7SspI5ERCGOP6pTtSW5swKdDqLI R+GJmyXp+ttyj2kquIy+4jwvn92b7qE= 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) From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20B=C3=A9rat?= 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in glibc. --- 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); -- 2.40.1