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: 1789096 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=qzbumyWi; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QX7lq4Rcqz20QB for ; Fri, 2 Jun 2023 00:28:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 896B0385773F for ; Thu, 1 Jun 2023 14:28:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 896B0385773F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685629701; 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=qzbumyWiamxM1ra7s3kXRWLZafigmybeFVNAoX4VujKzSswlBw3PVGxWjDlgRMy/t LYAQ2V5pzTU2MpgjKSsmlrTG2Og/cG5dX2Vx/j2g1JKU2dT2aVPJ4ImlOIBdpfBCNi W19sTQ0Isk8o4bOe2Qhm0GId0KFm05HVBcXlvkGw= 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+incoming=patchwork.ozlabs.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); From patchwork Thu Jun 1 14:27:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 1789097 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=h2nAoH6Z; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QX7lt0PLVz20QB for ; Fri, 2 Jun 2023 00:28:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 075643857034 for ; Thu, 1 Jun 2023 14:28:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 075643857034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685629704; bh=daop1qTq5BTcnBF6xWaNnAGldiMKotG1qiNWGBqNpwk=; 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=h2nAoH6ZXPMxwaVeEQrWKCRPO2X5ZnI5NgqcVluES4WAgv3qBMHpjOjuG5Pa0hZcE wiDarO+qRYSmTc6Kqfn5F6hwsFHwis6MnlIiAsP5SYn0VQYuo6cV6R7JtWwPp7mC0s HxU8gZMfrMeFbp5Q8qnRnWY1jdksYdyB0LOFiMwE= 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 9485B385840D for ; Thu, 1 Jun 2023 14:28:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9485B385840D 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-636-XU7WbzQyPmOH877eIwap_Q-1; Thu, 01 Jun 2023 10:28:06 -0400 X-MC-Unique: XU7WbzQyPmOH877eIwap_Q-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 9FD1D1C060D9; Thu, 1 Jun 2023 14:28:05 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC9048162; Thu, 1 Jun 2023 14:28:04 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v5 02/12] malloc/{memusage.c, memusagestat.c}: fix warn unused result Date: Thu, 1 Jun 2023 16:27:43 +0200 Message-Id: <20230601142747.104444-2-fberat@redhat.com> In-Reply-To: <20230418121130.844302-5-fberat@redhat.com> References: <20230601142747.104444-1-fberat@redhat.com> 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.7 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+incoming=patchwork.ozlabs.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 malloc/memusage.c | 54 +++++++++++++++++++++++++++++++++---------- malloc/memusagestat.c | 48 ++++++++++++++++++++++++++++++++++---- 2 files changed, 86 insertions(+), 16 deletions(-) diff --git a/malloc/memusage.c b/malloc/memusage.c index 2a3a508557..53a3630651 100644 --- a/malloc/memusage.c +++ b/malloc/memusage.c @@ -18,7 +18,10 @@ #include #include +#include +#include #include +#include #include #include #include @@ -142,6 +145,27 @@ peak_atomic_max (_Atomic size_t *peak, size_t val) while (! atomic_compare_exchange_weak (peak, &v, val)); } +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; + } +} + /* Update the global data after a successful function call. */ static void update_data (struct header *result, size_t len, size_t old_len) @@ -210,10 +234,11 @@ update_data (struct header *result, size_t len, size_t old_len) gettime (&buffer[idx]); /* Write out buffer if it is full. */ - if (idx + 1 == buffer_size) - write (fd, buffer, buffer_size * sizeof (struct entry)); - else if (idx + 1 == 2 * buffer_size) - write (fd, &buffer[buffer_size], buffer_size * sizeof (struct entry)); + if (idx + 1 == buffer_size || idx + 1 == 2 * buffer_size) + { + uint32_t write_size = buffer_size * sizeof (buffer[0]); + write_all (fd, &buffer[idx + 1 - buffer_size], write_size); + } } } @@ -299,8 +324,8 @@ me (void) first.stack = 0; gettime (&first); /* Write it two times since we need the starting and end time. */ - write (fd, &first, sizeof (first)); - write (fd, &first, sizeof (first)); + write_all (fd, &first, sizeof (first)); + write_all (fd, &first, sizeof (first)); /* Determine the buffer size. We use the default if the environment variable is not present. */ @@ -850,24 +875,29 @@ dest (void) if (fd != -1) { /* Write the partially filled buffer. */ + struct entry *start = buffer; + uint32_t write_cnt = buffer_cnt; + if (buffer_cnt > buffer_size) - write (fd, buffer + buffer_size, - (buffer_cnt - buffer_size) * sizeof (struct entry)); - else - write (fd, buffer, buffer_cnt * sizeof (struct entry)); + { + start = buffer + buffer_size; + write_cnt = buffer_cnt - buffer_size; + } + + write_all (fd, start, write_cnt * sizeof (buffer[0])); /* Go back to the beginning of the file. We allocated two records here when we opened the file. */ lseek (fd, 0, SEEK_SET); /* Write out a record containing the total size. */ first.stack = peak_total; - write (fd, &first, sizeof (struct entry)); + write_all (fd, &first, sizeof (first)); /* Write out another record containing the maximum for heap and stack. */ first.heap = peak_heap; first.stack = peak_stack; gettime (&first); - write (fd, &first, sizeof (struct entry)); + write_all (fd, &first, sizeof (first)); /* Close the file. */ close (fd); diff --git a/malloc/memusagestat.c b/malloc/memusagestat.c index 67c5131f79..cc066d4af9 100644 --- a/malloc/memusagestat.c +++ b/malloc/memusagestat.c @@ -114,6 +114,45 @@ static int time_based; static int also_total = 0; +static void +read_all (int fd, void *buffer, size_t length) +{ + char *p = buffer; + char *end = p + length; + while (p < end) + { + ssize_t ret = read (fd, p, end - p); + if (ret < 0) + error (EXIT_FAILURE, errno, + gettext ("read of %zu bytes failed after %td: %m"), + length, p - (char *) buffer); + + p += ret; + } +} + +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; + } +} + + int main (int argc, char *argv[]) { @@ -188,7 +227,7 @@ main (int argc, char *argv[]) total = st.st_size / sizeof (struct entry) - 2; /* Read the administrative information. */ - read (fd, headent, sizeof (headent)); + read_all (fd, headent, sizeof (headent)); maxsize_heap = headent[1].heap; maxsize_stack = headent[1].stack; maxsize_total = headent[0].stack; @@ -220,7 +259,8 @@ main (int argc, char *argv[]) /* Write the computed values in the file. */ lseek (fd, 0, SEEK_SET); - write (fd, headent, 2 * sizeof (struct entry)); + write_all (fd, headent, sizeof (headent)); + } if (also_total) @@ -372,7 +412,7 @@ main (int argc, char *argv[]) size_t new[2]; uint64_t now; - read (fd, &entry, sizeof (entry)); + read_all (fd, &entry, sizeof (entry)); now = ((uint64_t) entry.time_high) << 32 | entry.time_low; @@ -455,7 +495,7 @@ main (int argc, char *argv[]) size_t xpos; uint64_t now; - read (fd, &entry, sizeof (entry)); + read_all (fd, &entry, sizeof (entry)); now = ((uint64_t) entry.time_high) << 32 | entry.time_low; xpos = 40 + ((xsize - 80) * (now - start_time)) / total_time; From patchwork Thu Jun 1 14:27:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 1789099 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=e5zburKE; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QX7mN4WxWz20QB for ; Fri, 2 Jun 2023 00:28:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D88483856635 for ; Thu, 1 Jun 2023 14:28:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D88483856635 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685629728; bh=/TfhH6Ps2d01zASzAWpssP/VkHIqn3GxBL5fI+/1a34=; 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=e5zburKEMUb2S+XdG2uai/h1N75XHLy0ENJz3fka4CUid/K3OKKA6CaHq1VBKuKBm VVhItlkB3pwWhqGqBefv9G9swVWqevJwajFn21chWmZro/1RoW3bPRA9Hj39qtlpo+ YOk4qArAkGTQp2XZIx8gtlIsWAiI13broy4kKRIg= 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 DA0E93857346 for ; Thu, 1 Jun 2023 14:28:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA0E93857346 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-664--BGS2gznNnSrhDnp9q6dcw-1; Thu, 01 Jun 2023 10:28:06 -0400 X-MC-Unique: -BGS2gznNnSrhDnp9q6dcw-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 7F27B811E96; Thu, 1 Jun 2023 14:28:06 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA45D8162; Thu, 1 Jun 2023 14:28:05 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v5 03/12] nptl_db/thread_dbP.h: fix warn unused result Date: Thu, 1 Jun 2023 16:27:44 +0200 Message-Id: <20230601142747.104444-3-fberat@redhat.com> In-Reply-To: <20230418121130.844302-7-fberat@redhat.com> References: <20230601142747.104444-1-fberat@redhat.com> 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.5 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+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in glibc. Reviewed-by: Siddhesh Poyarekar --- Changes since v5: - Wrapped line since it exceeded 79 characters nptl_db/thread_dbP.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nptl_db/thread_dbP.h b/nptl_db/thread_dbP.h index 8845722109..b52c254300 100644 --- a/nptl_db/thread_dbP.h +++ b/nptl_db/thread_dbP.h @@ -61,7 +61,9 @@ enum /* Comment out the following for less verbose output. */ #ifndef NDEBUG -# define LOG(c) if (__td_debug) write (2, c "\n", strlen (c "\n")) +# define LOG(c) \ + if (__td_debug) \ + assert (write (2, c "\n", strlen (c "\n")) == strlen (c "\n")) extern int __td_debug attribute_hidden; #else # define LOG(c) From patchwork Thu Jun 1 14:27:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 1789100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=vxuM4pHR; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QX7mq0Jtrz20QB for ; Fri, 2 Jun 2023 00:29:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1106838558BE for ; Thu, 1 Jun 2023 14:29:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1106838558BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685629753; bh=+Rwdi6HclO/6EnKhuzxw9VKw3+PM7PA/BI0yEU3zzdU=; 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=vxuM4pHRQJxkBlRyU3eWw5FvM7rq9KmbY4DfNXBJAR96N3GMUrWV7/Nkb8TJDU/bx fYF5DSlOuZScbcf8eaeMKlA5isY6CmKBfvXcI0VzVLHnXM0UD9GfMGQH/E18wKY6d/ H7F7cgYxnLgpwObHB/fkBZLik0zzHwsIkSyiSJeA= 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 6937D3857438 for ; Thu, 1 Jun 2023 14:28:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6937D3857438 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-516-vJiNLnihPNabs8riUC02uQ-1; Thu, 01 Jun 2023 10:28:09 -0400 X-MC-Unique: vJiNLnihPNabs8riUC02uQ-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 6196B80120A; Thu, 1 Jun 2023 14:28:08 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B97299E63; Thu, 1 Jun 2023 14:28:06 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v5 04/12] tests: fix warn unused result on asprintf calls Date: Thu, 1 Jun 2023 16:27:45 +0200 Message-Id: <20230601142747.104444-4-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-fberat@redhat.com> References: <20230601142747.104444-1-fberat@redhat.com> 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.2 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, 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+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" When enabling _FORTIFY_SOURCE, some functions now lead to warnings when their result is not checked. --- Changes since v4: - Properly use xasprintf in all cases in posix/tst-execlp2.c argp/argp-test.c | 8 +++++--- posix/tst-execl2.c | 8 ++------ posix/tst-execle2.c | 8 ++------ posix/tst-execlp2.c | 10 +++------- posix/tst-execv2.c | 8 ++------ posix/tst-execve2.c | 8 ++------ posix/tst-execvp2.c | 17 ++++------------- stdio-common/bug5.c | 4 +++- stdio-common/test-fwrite.c | 4 +++- stdio-common/tst-fseek.c | 5 ++--- 10 files changed, 28 insertions(+), 52 deletions(-) diff --git a/argp/argp-test.c b/argp/argp-test.c index c7e20f6235..cd69c81b1a 100644 --- a/argp/argp-test.c +++ b/argp/argp-test.c @@ -25,6 +25,8 @@ #include #include +#include + const char *argp_program_version = "argp-test 1.0"; struct argp_option sub_options[] = @@ -178,12 +180,12 @@ help_filter (int key, const char *text, void *input) if (key == ARGP_KEY_HELP_POST_DOC && text) { time_t now = time (0); - asprintf (&new_text, text, ctime (&now)); + new_text = xasprintf (text, ctime (&now)); } else if (key == 'f') /* Show the default for the --foonly option. */ - asprintf (&new_text, "%s (ZOT defaults to %x)", - text, params->foonly_default); + new_text = xasprintf ("%s (ZOT defaults to %x)", + text, params->foonly_default); else new_text = (char *)text; diff --git a/posix/tst-execl2.c b/posix/tst-execl2.c index 5b74959ef8..d2f4453ad8 100644 --- a/posix/tst-execl2.c +++ b/posix/tst-execl2.c @@ -18,12 +18,8 @@ prepare (int argc, char *argv[]) { char *buf; int off; - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); - if (buf == NULL) - { - puts ("asprintf failed"); - exit (1); - } + + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); if (system (buf) != 0) { puts ("system failed"); diff --git a/posix/tst-execle2.c b/posix/tst-execle2.c index 0430b7b573..8e3ad9acb6 100644 --- a/posix/tst-execle2.c +++ b/posix/tst-execle2.c @@ -18,12 +18,8 @@ prepare (int argc, char *argv[]) { char *buf; int off; - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); - if (buf == NULL) - { - puts ("asprintf failed"); - exit (1); - } + + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); if (system (buf) != 0) { puts ("system failed"); diff --git a/posix/tst-execlp2.c b/posix/tst-execlp2.c index 81a723dda4..b42037babd 100644 --- a/posix/tst-execlp2.c +++ b/posix/tst-execlp2.c @@ -22,12 +22,8 @@ prepare (int argc, char *argv[]) { char *buf; int off; - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); - if (buf == NULL) - { - puts ("asprintf failed"); - exit (1); - } + + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); if (system (buf) != 0) { puts ("system failed"); @@ -59,7 +55,7 @@ do_test (void) return 1; } char *path; - asprintf (&path, "%s:../libio:../elf", bindir); + path = xasprintf ("%s:../libio:../elf", bindir); if (path == NULL) { puts ("asprintf failed"); diff --git a/posix/tst-execv2.c b/posix/tst-execv2.c index a5168a269c..5fd6c46c1f 100644 --- a/posix/tst-execv2.c +++ b/posix/tst-execv2.c @@ -18,12 +18,8 @@ prepare (int argc, char *argv[]) { char *buf; int off; - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); - if (buf == NULL) - { - puts ("asprintf failed"); - exit (1); - } + + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); if (system (buf) != 0) { puts ("system failed"); diff --git a/posix/tst-execve2.c b/posix/tst-execve2.c index 1a804e94fd..e0a7c84346 100644 --- a/posix/tst-execve2.c +++ b/posix/tst-execve2.c @@ -18,12 +18,8 @@ prepare (int argc, char *argv[]) { char *buf; int off; - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); - if (buf == NULL) - { - puts ("asprintf failed"); - exit (1); - } + + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); if (system (buf) != 0) { puts ("system failed"); diff --git a/posix/tst-execvp2.c b/posix/tst-execvp2.c index 440dfab438..f6c0cb4d98 100644 --- a/posix/tst-execvp2.c +++ b/posix/tst-execvp2.c @@ -25,12 +25,8 @@ prepare (int argc, char *argv[]) { char *buf; int off; - asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]); - if (buf == NULL) - { - puts ("asprintf failed"); - exit (1); - } + + buf = xasprintf ("cp %s %n%s-copy", argv[0], &off, argv[0]); if (system (buf) != 0) { puts ("system failed"); @@ -61,13 +57,8 @@ do_test (void) puts ("canonicalize_file_name failed"); return 1; } - char *path; - asprintf (&path, "%s:../libio:../elf", bindir); - if (path == NULL) - { - puts ("asprintf failed"); - return 1; - } + + char *path = xasprintf ("%s:../libio:../elf", bindir); setenv ("PATH", path, 1); diff --git a/stdio-common/bug5.c b/stdio-common/bug5.c index 7bfe9b2b8d..dfa19aed55 100644 --- a/stdio-common/bug5.c +++ b/stdio-common/bug5.c @@ -7,6 +7,8 @@ #include #include +#include + static char buf[8192]; int @@ -60,7 +62,7 @@ main (void) the perhaps incompatible new shared libraries. */ unsetenv ("LD_LIBRARY_PATH"); - asprintf (&printbuf, "cmp %s %s", inname, outname); + printbuf = xasprintf ("cmp %s %s", inname, outname); result = system (printbuf); remove (inname); remove (outname); diff --git a/stdio-common/test-fwrite.c b/stdio-common/test-fwrite.c index 5677c6da80..7f383921ca 100644 --- a/stdio-common/test-fwrite.c +++ b/stdio-common/test-fwrite.c @@ -1,6 +1,8 @@ #include #include +#include + static int do_test (void) { @@ -57,7 +59,7 @@ do_test (void) return 1; } - asprintf (&line, "\ + line = xasprintf ("\ GDB is free software and you are welcome to distribute copies of it\n\ under certain conditions; type \"show copying\" to see the conditions.\n\ There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\ diff --git a/stdio-common/tst-fseek.c b/stdio-common/tst-fseek.c index c4ac17cdf4..386dd1dd51 100644 --- a/stdio-common/tst-fseek.c +++ b/stdio-common/tst-fseek.c @@ -25,6 +25,7 @@ #include #include +#include static int do_test (void) @@ -44,9 +45,7 @@ do_test (void) if (tmpdir == NULL || tmpdir[0] == '\0') tmpdir = "/tmp"; - asprintf (&fname, "%s/tst-fseek.XXXXXX", tmpdir); - if (fname == NULL) - error (EXIT_FAILURE, errno, "cannot generate name for temporary file"); + fname = xasprintf ("%s/tst-fseek.XXXXXX", tmpdir); /* Create a temporary file. */ fd = mkstemp (fname); From patchwork Thu Jun 1 14:27:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 1789101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=sutF2BXG; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QX7mq727gz20QB for ; Fri, 2 Jun 2023 00:29:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DBD8A385C6CE for ; Thu, 1 Jun 2023 14:29:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DBD8A385C6CE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685629753; bh=bT/vqIBPym6npspHlnXDxPNaDUDqVks5uxOYeawVOzs=; 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=sutF2BXG+fCVvCgLqsjbjIKLamomc52bP/C+5M7QhD8LT/sUAI/xntn/QCygR2iq4 78dSOe/T8sa6GMuNVrktO1nUItU/sKiva2ZE+wMd0/XQTiBqmIl+zvHQajFqfEkdjf FR9HxxPrnjJ/ePAFsbbVG/nBblCHmyFrjARhYEmI= 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 D46BB3858421 for ; Thu, 1 Jun 2023 14:28:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D46BB3858421 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-524-j41sMi6AP5quHlwUbkwUgQ-1; Thu, 01 Jun 2023 10:28:09 -0400 X-MC-Unique: j41sMi6AP5quHlwUbkwUgQ-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 40C5085A5AA; Thu, 1 Jun 2023 14:28:09 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9BBD89E72; Thu, 1 Jun 2023 14:28:08 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v5 07/12] tests: replace system by xsystem Date: Thu, 1 Jun 2023 16:27:46 +0200 Message-Id: <20230601142747.104444-5-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-fberat@redhat.com> References: <20230601142747.104444-1-fberat@redhat.com> 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, KAM_SHORT, 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+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" With fortification enabled, system calls return result needs to be checked, has it gets the __wur macro enabled. --- Changes since v4: - Added more fail case in xsystem - Clarify why some system calls should not use xsystem elf/tst-stackguard1.c | 3 ++- libio/bug-mmap-fflush.c | 7 +++++-- nptl/tst-cancel7.c | 3 ++- nptl/tst-stackguard1.c | 3 ++- nss/tst-nss-db-endpwent.c | 3 ++- support/Makefile | 1 + support/xstdlib.h | 31 +++++++++++++++++++++++++++++++ support/xsystem.c | 37 +++++++++++++++++++++++++++++++++++++ 8 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 support/xstdlib.h create mode 100644 support/xsystem.c diff --git a/elf/tst-stackguard1.c b/elf/tst-stackguard1.c index 2e65e36078..1919ae8682 100644 --- a/elf/tst-stackguard1.c +++ b/elf/tst-stackguard1.c @@ -108,7 +108,8 @@ do_test (void) dup2 (fds[1], 2); close (fds[1]); - system (command); + if (system (command)) {/* Should actually fail */} + exit (0); } diff --git a/libio/bug-mmap-fflush.c b/libio/bug-mmap-fflush.c index d8aa58985a..3f99222eef 100644 --- a/libio/bug-mmap-fflush.c +++ b/libio/bug-mmap-fflush.c @@ -4,6 +4,7 @@ #include #include +#include static char *fname; @@ -35,14 +36,16 @@ do_test (void) char buffer[1024]; snprintf (buffer, sizeof (buffer), "echo 'From foo@bar.com' > %s", fname); - system (buffer); + xsystem (buffer); + f = fopen (fname, "r"); fseek (f, 0, SEEK_END); o = ftello (f); fseek (f, 0, SEEK_SET); fflush (f); snprintf (buffer, sizeof (buffer), "echo 'From bar@baz.edu' >> %s", fname); - system (buffer); + xsystem (buffer); + fseek (f, o, SEEK_SET); if (fgets (buffer, 1024, f) == NULL) exit (1); diff --git a/nptl/tst-cancel7.c b/nptl/tst-cancel7.c index 2835613a9b..0ecb7d025f 100644 --- a/nptl/tst-cancel7.c +++ b/nptl/tst-cancel7.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ tf (void *arg) { char *cmd = xasprintf ("%s --direct --sem %s --pidfile %s", command, semfilename, pidfilename); - system (cmd); + xsystem (cmd); /* This call should never return. */ return NULL; } diff --git a/nptl/tst-stackguard1.c b/nptl/tst-stackguard1.c index 4ac57157e9..5ca719ed32 100644 --- a/nptl/tst-stackguard1.c +++ b/nptl/tst-stackguard1.c @@ -140,7 +140,8 @@ do_test (void) dup2 (fds[1], 2); close (fds[1]); - system (command); + if (system (command)) {/* Should actually fail */} + exit (0); } diff --git a/nss/tst-nss-db-endpwent.c b/nss/tst-nss-db-endpwent.c index 2b0fc1b064..4dba3fada6 100644 --- a/nss/tst-nss-db-endpwent.c +++ b/nss/tst-nss-db-endpwent.c @@ -23,6 +23,7 @@ #include #include +#include /* It is entirely allowed to start with a getpwent call without resetting the state of the service via a call to setpwent. @@ -55,7 +56,7 @@ do_test (void) cmd = xasprintf ("%s/makedb -o /var/db/passwd.db /var/db/passwd.in", support_bindir_prefix); - system (cmd); + xsystem (cmd); free (cmd); try_it (); diff --git a/support/Makefile b/support/Makefile index c3d16d25b3..f51c2e03a8 100644 --- a/support/Makefile +++ b/support/Makefile @@ -209,6 +209,7 @@ libsupport-routines = \ xstrdup \ xstrndup \ xsymlink \ + xsystem \ xsysconf \ xunlink \ xuselocale \ diff --git a/support/xstdlib.h b/support/xstdlib.h new file mode 100644 index 0000000000..58642e3542 --- /dev/null +++ b/support/xstdlib.h @@ -0,0 +1,31 @@ +/* Error-checking wrappers for stdlib functions. + Copyright (C) 2016-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef SUPPORT_XSTDLIB_H +#define SUPPORT_XSTDLIB_H + +#include +#include + +__BEGIN_DECLS + +void xsystem (const char *cmd); + +__END_DECLS + +#endif /* SUPPORT_XSTDLIB_H */ diff --git a/support/xsystem.c b/support/xsystem.c new file mode 100644 index 0000000000..efa26ed772 --- /dev/null +++ b/support/xsystem.c @@ -0,0 +1,37 @@ +/* Error-checking replacement for "system". + Copyright (C) 2018-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +#include + +void +xsystem (const char *cmd) +{ + int ret = system (cmd); + + if (ret == 0 && cmd == NULL) + FAIL_EXIT1 ("Unable to spawn a shell for NULL command"); + + if (ret == 127) + FAIL_EXIT1 ("Child terminated with status 127"); + + if (ret < 0) + FAIL_EXIT1 ("system (\"%s\")", cmd); +} From patchwork Thu Jun 1 14:27:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 1789098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=YZWqtAZk; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QX7lz5xDnz20QB for ; Fri, 2 Jun 2023 00:28:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C7F1F3856965 for ; Thu, 1 Jun 2023 14:28:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7F1F3856965 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685629709; bh=ftuZK6SaRmc4Zhf34xI220n09A7xUlD9sKmddoA4E5Y=; 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=YZWqtAZkUae+uWxFpgqXJcSc8JqWNRtvoafKH/frb6NSFoLZKHmp4bh5+62BGX2Zo Atq0lYAxzUQu/IApB1x0QGdmV8PDOa/TG1pte9uOdmmSJHKqb2PnBgKGinz8RAU5l5 BZQtDQRvKRzLr9XdhghhZdTj/sFxoqYIWa6u4VtY= 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 49CEB3857C4F for ; Thu, 1 Jun 2023 14:28:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49CEB3857C4F 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-570-7eeuQ3-xM9WDJn9ziEIt4A-1; Thu, 01 Jun 2023 10:28:10 -0400 X-MC-Unique: 7eeuQ3-xM9WDJn9ziEIt4A-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 416EB101A55C; Thu, 1 Jun 2023 14:28:10 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D10D8162; Thu, 1 Jun 2023 14:28:09 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v5 12/12] tests: fix warn unused results Date: Thu, 1 Jun 2023 16:27:47 +0200 Message-Id: <20230601142747.104444-6-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-fberat@redhat.com> References: <20230601142747.104444-1-fberat@redhat.com> 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+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" With fortification enabled, few function calls return result need to be checked, has they get the __wur macro enabled. Reviewed-by: Siddhesh Poyarekar --- Changes since v4: - Removed extra curly brackets crypt/cert.c | 6 +++++- misc/tst-efgcvt-template.c | 4 ++-- posix/tst-nice.c | 3 +-- posix/wordexp-test.c | 6 +++++- stdio-common/bug19.c | 9 +++++++-- stdio-common/bug6.c | 8 ++++---- stdio-common/tstscanf.c | 14 ++++++++++++-- stdlib/test-canon.c | 16 +++++++++++++--- support/test-container.c | 4 ++-- sysdeps/pthread/tst-cancel16.c | 6 +++++- sysdeps/pthread/tst-cancel4.c | 6 ++++-- 11 files changed, 60 insertions(+), 22 deletions(-) diff --git a/crypt/cert.c b/crypt/cert.c index 32c4386caf..5b4277f76d 100644 --- a/crypt/cert.c +++ b/crypt/cert.c @@ -99,7 +99,11 @@ get8 (char *cp) int i,j,t; for(i=0;i<8;i++){ - scanf("%2x",&t); + if (scanf("%2x",&t) < 1) + { + if(ferror(stdin)) + totfails++; + } if(feof(stdin)) good_bye(); for(j=0; j<8 ; j++) { diff --git a/misc/tst-efgcvt-template.c b/misc/tst-efgcvt-template.c index b924659a3d..87e3ebe4fa 100644 --- a/misc/tst-efgcvt-template.c +++ b/misc/tst-efgcvt-template.c @@ -200,8 +200,8 @@ special (void) output_error (NAME (ECVT), INFINITY, 10, "inf", 0, 0, p, decpt, sign); /* Simply make sure these calls with large NDIGITs don't crash. */ - (void) ECVT (123.456, 10000, &decpt, &sign); - (void) FCVT (123.456, 10000, &decpt, &sign); + p = ECVT (123.456, 10000, &decpt, &sign); + p = FCVT (123.456, 10000, &decpt, &sign); /* Some tests for the reentrant functions. */ /* Use a too small buffer. */ diff --git a/posix/tst-nice.c b/posix/tst-nice.c index fe9888b3f6..59cf953e27 100644 --- a/posix/tst-nice.c +++ b/posix/tst-nice.c @@ -58,8 +58,7 @@ do_test (void) /* BZ #18086. Make sure we don't reset errno. */ errno = EBADF; - nice (0); - if (errno != EBADF) + if (nice (0) == -1 || errno != EBADF) { printf ("FAIL: errno = %i, but wanted EBADF (%i)\n", errno, EBADF); return 1; diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c index 87d537c931..057c89dd3c 100644 --- a/posix/wordexp-test.c +++ b/posix/wordexp-test.c @@ -253,7 +253,11 @@ do_test (int argc, char *argv[]) cwd = getcwd (NULL, 0); /* Set up arena for pathname expansion */ - tmpnam (tmpdir); + if (!tmpnam (tmpdir)) + { + printf ("Failed to create a temporary directory with a unique name: %m"); + return 1; + } xmkdir (tmpdir, S_IRWXU); TEST_VERIFY_EXIT (chdir (tmpdir) == 0); diff --git a/stdio-common/bug19.c b/stdio-common/bug19.c index e083304bda..9a3deac3fc 100644 --- a/stdio-common/bug19.c +++ b/stdio-common/bug19.c @@ -29,12 +29,17 @@ do_test (void) printf("checking sscanf\n"); int i, j, n; + int result = 0; i = j = n = 0; - FSCANF (fp, L(" %i - %i %n"), &i, &j, &n); + if (FSCANF (fp, L(" %i - %i %n"), &i, &j, &n) < 2) + { + printf ("FSCANF couldn't read all parameters %d\n", errno); + result = 1; + } + printf ("found %i-%i (length=%i)\n", i, j, n); - int result = 0; if (i != 7) { printf ("i is %d, expected 7\n", i); diff --git a/stdio-common/bug6.c b/stdio-common/bug6.c index 0db63a3b44..50098bf3f2 100644 --- a/stdio-common/bug6.c +++ b/stdio-common/bug6.c @@ -7,16 +7,16 @@ main (void) int i; int lost = 0; - scanf ("%2s", buf); + lost = (scanf ("%2s", buf) < 0); lost |= (buf[0] != 'X' || buf[1] != 'Y' || buf[2] != '\0'); if (lost) puts ("test of %2s failed."); - scanf (" "); - scanf ("%d", &i); + lost |= (scanf (" ") < 0); + lost |= (scanf ("%d", &i) < 0); lost |= (i != 1234); if (lost) puts ("test of %d failed."); - scanf ("%c", buf); + lost |= (scanf ("%c", buf) < 0); lost |= (buf[0] != 'L'); if (lost) puts ("test of %c failed.\n"); diff --git a/stdio-common/tstscanf.c b/stdio-common/tstscanf.c index 3a4ebf7524..7e92df4720 100644 --- a/stdio-common/tstscanf.c +++ b/stdio-common/tstscanf.c @@ -120,7 +120,12 @@ main (int argc, char **argv) int i; float x; char name[50]; - (void) fscanf (in, "%2d%f%*d %[0123456789]", &i, &x, name); + if (fscanf (in, "%2d%f%*d %[0123456789]", &i, &x, name) < 3) + { + fputs ("test failed!\n", stdout); + result = 1; + } + fprintf (out, "i = %d, x = %f, name = \"%.50s\"\n", i, x, name); if (i != 56 || x != 789.0F || strcmp (name, "56")) { @@ -164,7 +169,12 @@ main (int argc, char **argv) quant = 0.0; units[0] = item[0] = '\0'; count = fscanf (in, "%f%20s of %20s", &quant, units, item); - (void) fscanf (in, "%*[^\n]"); + if (fscanf (in, "%*[^\n]") < 0 && ferror (in)) + { + fputs ("test failed!\n", stdout); + result = 1; + } + fprintf (out, "count = %d, quant = %f, item = %.21s, units = %.21s\n", count, quant, item, units); if (count != ok[rounds-1].count || quant != ok[rounds-1].quant diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c index 5a2e7e1e6e..407ad5c4a2 100644 --- a/stdlib/test-canon.c +++ b/stdlib/test-canon.c @@ -123,8 +123,13 @@ do_test (int argc, char ** argv) int i, errors = 0; char buf[PATH_MAX]; - getcwd (cwd, sizeof (buf)); - cwd_len = strlen (cwd); + if (getcwd (cwd, sizeof (buf))) + cwd_len = strlen (cwd); + else + { + printf ("%s: current working directory couldn't be retrieved\n", argv[0]); + ++errors; + } errno = 0; if (realpath (NULL, buf) != NULL || errno != EINVAL) @@ -210,7 +215,12 @@ do_test (int argc, char ** argv) free (result2); } - getcwd (buf, sizeof (buf)); + if (!getcwd (buf, sizeof (buf))) + { + printf ("%s: current working directory couldn't be retrieved\n", argv[0]); + ++errors; + } + if (strcmp (buf, cwd)) { printf ("%s: current working directory changed from %s to %s\n", diff --git a/support/test-container.c b/support/test-container.c index 37beb778d6..f51afefedb 100644 --- a/support/test-container.c +++ b/support/test-container.c @@ -714,8 +714,8 @@ check_for_unshare_hints (int require_pidns) continue; val = -1; /* Sentinel. */ - fscanf (f, "%d", &val); - if (val != files[i].bad_value) + int cnt = fscanf (f, "%d", &val); + if (cnt == 1 && val != files[i].bad_value) continue; printf ("To enable test-container, please run this as root:\n"); diff --git a/sysdeps/pthread/tst-cancel16.c b/sysdeps/pthread/tst-cancel16.c index 511b9e1e91..d47c7c68cb 100644 --- a/sysdeps/pthread/tst-cancel16.c +++ b/sysdeps/pthread/tst-cancel16.c @@ -50,7 +50,11 @@ tf (void *arg) pthread_cleanup_push (cl, NULL); /* This call should never return. */ - (void) lockf (fd, F_LOCK, 0); + if (lockf (fd, F_LOCK, 0)) + { + puts ("child thread: lockf failed"); + exit (1); + } pthread_cleanup_pop (0); diff --git a/sysdeps/pthread/tst-cancel4.c b/sysdeps/pthread/tst-cancel4.c index 4f5c89314c..4c9e8670ca 100644 --- a/sysdeps/pthread/tst-cancel4.c +++ b/sysdeps/pthread/tst-cancel4.c @@ -1009,7 +1009,8 @@ tf_pread (void *arg) pthread_cleanup_push (cl, NULL); char mem[10]; - pread (tempfd, mem, sizeof (mem), 0); + if (pread (tempfd, mem, sizeof (mem), 0) < 0) + FAIL_EXIT1 ("pread failed: %m"); pthread_cleanup_pop (0); @@ -1038,7 +1039,8 @@ tf_pwrite (void *arg) pthread_cleanup_push (cl, NULL); char mem[10]; - pwrite (tempfd, mem, sizeof (mem), 0); + if (pwrite (tempfd, mem, sizeof (mem), 0) <0) + FAIL_EXIT1 ("pwrite failed: %m"); pthread_cleanup_pop (0);