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); From patchwork Fri Apr 28 12:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68469 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 2DB9E385771E for ; Fri, 28 Apr 2023 12:35:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DB9E385771E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685357; bh=qIvFx/lwDgz1VYDAnTthnIWSFYJEcmm8bFUw7WILqSM=; 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=nHKmA9FCu5EhOyX0gbgH0y+j4OxAfb4Vr0Uk+BN8h/J2JYp0y/wSh2ztfkdPwVl8q 2LrjjBZDled1kBM+xEWgY3c5tnTqn2Pg1RcGcDwzbfLJeUIkfcxhGH0X1pNZiqSIBi BKrV3eiTSG30SscPDnD6oJoB4MSTtX5dvNhs6qKg= 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 2C8693858C66 for ; Fri, 28 Apr 2023 12:35:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C8693858C66 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-437-1RAMHJeaPZ-UE55JXpktlw-1; Fri, 28 Apr 2023 08:35:23 -0400 X-MC-Unique: 1RAMHJeaPZ-UE55JXpktlw-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 F07E81078508; 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 564BEC15BA0; Fri, 28 Apr 2023 12:35:22 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 02/15] locale/programs/locarchive.c: fix warn unused result Date: Fri, 28 Apr 2023 14:21:29 +0200 Message-Id: <20230428122142.928135-3-fberat@redhat.com> In-Reply-To: <20230418121130.844302-5-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.0 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" Changes since v2: - Freeing normalized_codeset before returning. Changes since v3: - Rebased on master --8<-- Fix unused result warnings, detected when _FORTIFY_SOURCE is enabled in glibc. Reviewed-by: Siddhesh Poyarekar --- locale/programs/locarchive.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c index 8d7d51af6c..71fd9f34fa 100644 --- a/locale/programs/locarchive.c +++ b/locale/programs/locarchive.c @@ -1154,10 +1154,14 @@ add_locale_to_archive (struct locarhandle *ah, const char *name, if (mask & XPG_NORM_CODESET) /* This name contains a codeset in unnormalized form. We will store it in the archive with a normalized name. */ - asprintf (&normalized_name, "%s%s%s.%s%s%s", - language, territory == NULL ? "" : "_", territory ?: "", - normalized_codeset, - modifier == NULL ? "" : "@", modifier ?: ""); + if (asprintf (&normalized_name, "%s%s%s.%s%s%s", + language, territory == NULL ? "" : "_", territory ?: "", + normalized_codeset, + modifier == NULL ? "" : "@", modifier ?: "") < 0) + { + free ((char *) normalized_codeset); + return -1; + } /* This call does the main work. */ locrec_offset = add_locale (ah, normalized_name ?: name, data, replace); @@ -1188,10 +1192,14 @@ add_locale_to_archive (struct locarhandle *ah, const char *name, normalized_codeset = _nl_normalize_codeset (codeset, strlen (codeset)); mask |= XPG_NORM_CODESET; - asprintf (&normalized_codeset_name, "%s%s%s.%s%s%s", - language, territory == NULL ? "" : "_", territory ?: "", - normalized_codeset, - modifier == NULL ? "" : "@", modifier ?: ""); + if (asprintf (&normalized_codeset_name, "%s%s%s.%s%s%s", + language, territory == NULL ? "" : "_", territory ?: "", + normalized_codeset, + modifier == NULL ? "" : "@", modifier ?: "") < 0) + { + free ((char *) normalized_codeset); + return -1; + } add_alias (ah, normalized_codeset_name, replace, normalized_name ?: name, &locrec_offset); From patchwork Fri Apr 28 12:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68470 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 3D6783856DC4 for ; Fri, 28 Apr 2023 12:36:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D6783856DC4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685371; bh=CuaxCqlVufYj6Y8VDf3+h48iGIYzz3Agzz48jyTF4Rk=; 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=idpKLGF99cpJ0nr3ZoiQ0XWj65YhuCevU51rr8gtgca595Ti6N2Xvp8JKwwHocVgl mpP9RLoYsST3RJcCkKr4nDig4CvSrRYuNKQTF/vEp/38UQSnu9X9wHOsdx7rFPNH+T QpjOWGlOoVabGqc2CoGHRJxOJuUyhiygIXMyz57Y= 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 D30683858C78 for ; Fri, 28 Apr 2023 12:35:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D30683858C78 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-375-JFYKy6HJOM22F8hA98UJRg-1; Fri, 28 Apr 2023 08:35:24 -0400 X-MC-Unique: JFYKy6HJOM22F8hA98UJRg-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 D31B21C05AB9; Fri, 28 Apr 2023 12:35:23 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 37CB7C15BA0; Fri, 28 Apr 2023 12:35:23 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 03/15] malloc/{memusage.c, memusagestat.c}: fix warn unused result Date: Fri, 28 Apr 2023 14:21:30 +0200 Message-Id: <20230428122142.928135-4-fberat@redhat.com> In-Reply-To: <20230418121130.844302-6-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.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, 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. --- malloc/memusage.c | 53 +++++++++++++++++++++++++++++++++---------- malloc/memusagestat.c | 48 +++++++++++++++++++++++++++++++++++---- 2 files changed, 85 insertions(+), 16 deletions(-) diff --git a/malloc/memusage.c b/malloc/memusage.c index 2a3a508557..0c414b0e85 100644 --- a/malloc/memusage.c +++ b/malloc/memusage.c @@ -18,6 +18,8 @@ #include #include +#include +#include #include #include #include @@ -142,6 +144,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, + "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; + } +} + /* 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 +233,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 +323,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 +874,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..9fe6dba2d8 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, + "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, + "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; + } +} + + 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 Fri Apr 28 12:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68473 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 6E3BE3850206 for ; Fri, 28 Apr 2023 12:36:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E3BE3850206 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685404; bh=2bP4Uh1YJG2ccOzO7JqPvbHW/SzgA6djf/e19D0gN8w=; 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=Chh5WJBvvgelZQ8SkA0K7u+++kWIr+OExU5J++Cq3vnpWXSLPoHWSrM1kB0nxheGH 0A8aYrkcEaoq+Iw2JkX4U3IMrec/H7feOPVo58nESaiq0ma72PeWueVkzQarPMv8tM bmHDVbdi7jD1+dduBeY5txjfFJT9Pde5pm5mCLq0= 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 55D523858418 for ; Fri, 28 Apr 2023 12:35:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55D523858418 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-441-JpbCRzDGNxK6WkkSn5Y4gA-1; Fri, 28 Apr 2023 08:35:25 -0400 X-MC-Unique: JpbCRzDGNxK6WkkSn5Y4gA-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 B7FC085A588; Fri, 28 Apr 2023 12:35:24 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1A751C15BA0; Fri, 28 Apr 2023 12:35:23 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 04/15] nptl_db/thread_dbP.h: fix warn unused result Date: Fri, 28 Apr 2023 14:21:31 +0200 Message-Id: <20230428122142.928135-5-fberat@redhat.com> In-Reply-To: <20230418121130.844302-7-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.1 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. Reviewed-by: Siddhesh Poyarekar --- nptl_db/thread_dbP.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nptl_db/thread_dbP.h b/nptl_db/thread_dbP.h index 8845722109..4a9333658b 100644 --- a/nptl_db/thread_dbP.h +++ b/nptl_db/thread_dbP.h @@ -61,7 +61,7 @@ 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 Fri Apr 28 12:21:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68475 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 93B833881D07 for ; Fri, 28 Apr 2023 12:37:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 93B833881D07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685443; bh=ECEuohSEh8DSmfaYqbsVTvTADb7Wbub4SJfJAwkD/YA=; 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=gugH3f8+1mes2n5/sHq+oxwQ/o3rd8Rlk/ctanJ9vxLDHOEO0d6AbrA+2pM71yWg0 QaEpIjhCBuo2rzrowLa7GSxBURWaReBKF0OM4pJCvPzgYZ89WsMCYkgHAL8kjeQ9ie 5dRufBjVeRPKHx3g8bhGbG8a8nUYEDIKXmoGJY88= 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 5ED59385843E for ; Fri, 28 Apr 2023 12:35:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5ED59385843E 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-445-56SgpRHsMTaVbKap85Bz6Q-1; Fri, 28 Apr 2023 08:35:26 -0400 X-MC-Unique: 56SgpRHsMTaVbKap85Bz6Q-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 993DC3822DEE; Fri, 28 Apr 2023 12:35:25 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F2C52C15BA0; Fri, 28 Apr 2023 12:35:24 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 05/15] sunrpc/netname.c: fix warn unused result Date: Fri, 28 Apr 2023 14:21:32 +0200 Message-Id: <20230428122142.928135-6-fberat@redhat.com> In-Reply-To: <20230418121130.844302-8-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.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, 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. Reviewed-by: Siddhesh Poyarekar --- sunrpc/netname.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sunrpc/netname.c b/sunrpc/netname.c index dd2cb1b441..d9d82501b0 100644 --- a/sunrpc/netname.c +++ b/sunrpc/netname.c @@ -96,7 +96,8 @@ host2netname (char netname[MAXNETNAMELEN + 1], const char *host, else { domainname[0] = 0; - getdomainname (domainname, MAXHOSTNAMELEN); + if (getdomainname (domainname, MAXHOSTNAMELEN)) + return 0; } } else From patchwork Fri Apr 28 12:21:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68476 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 EE1BE3852757 for ; Fri, 28 Apr 2023 12:37:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE1BE3852757 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685451; bh=U4wl2yuFKJhOE7UFYcF5kGoFuHKKKxJ/LYFjeXORZz8=; 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=Cy2AeWaiBJCuQpU9nQUBMFd1XYqbaVL3k2YA8ptOnxcg8KPl0AyxuZOxnrA7mhO4w 0onDbuwftTwrZPYjpO5LBlP+FCXKRtZFFBzJiLqvPBJXv+BPt2ku6cMJWz3wLzVQ5/ I/dR/gJRFHcttB8skOw/3D4DrbdjwXloJzBqiOLY= 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 363FF3858425 for ; Fri, 28 Apr 2023 12:35:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 363FF3858425 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-393-U24UPfiUNYmdW82hlxvIGQ-1; Fri, 28 Apr 2023 08:35:26 -0400 X-MC-Unique: U24UPfiUNYmdW82hlxvIGQ-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 800CD887400; Fri, 28 Apr 2023 12:35:26 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4AFFC15BA0; Fri, 28 Apr 2023 12:35:25 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 06/15] sysdeps/pthread/eintr.c: fix warn unused result Date: Fri, 28 Apr 2023 14:21:33 +0200 Message-Id: <20230428122142.928135-7-fberat@redhat.com> In-Reply-To: <20230418121130.844302-9-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.1 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. Reviewed-by: Siddhesh Poyarekar --- sysdeps/pthread/eintr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sysdeps/pthread/eintr.c b/sysdeps/pthread/eintr.c index 000649d24e..16191395a7 100644 --- a/sysdeps/pthread/eintr.c +++ b/sysdeps/pthread/eintr.c @@ -31,10 +31,12 @@ eintr_handler (int sig) { if (sig != the_sig) { - write (STDOUT_FILENO, "eintr_handler: signal number wrong\n", 35); + /* empty if statement avoids warn unused result */ + if (write (STDOUT_FILENO, + "eintr_handler: signal number wrong\n", 35) < 35) {}; _exit (1); } - write (STDOUT_FILENO, ".", 1); + if (write (STDOUT_FILENO, ".", 1)) {/* Avoid warn unused result */}; } From patchwork Fri Apr 28 12:21:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68479 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 A6D0538708C8 for ; Fri, 28 Apr 2023 12:38:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6D0538708C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685490; bh=xWiSJmKtYaTRb9JtxCUViuHfXoxuEpzvmdSZb8vel6A=; 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=Whthpv59NxKg8oH6XiiYM9OnyI3YIz001ekC+1lW3a5IT8Fil8kgLT7VqG3mdsRmP hGZpd6TFzfdIXaXVLbKUg/Du+Ai3uEHXbM2uJ/fgffRfgtLFC9EqFw1n6eNJoDF4zV dGlAZ6sztshMY/oDEwa1iibQ742t5jcuIU/W+lQk= 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 8BEF0385783F for ; Fri, 28 Apr 2023 12:35:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8BEF0385783F 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-370-c-ZVsgNRPSOWzv-PkgcJGw-1; Fri, 28 Apr 2023 08:35:27 -0400 X-MC-Unique: c-ZVsgNRPSOWzv-PkgcJGw-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 7FAA088B7A6; Fri, 28 Apr 2023 12:35:27 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB692C16024; Fri, 28 Apr 2023 12:35:26 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 07/15] tests: fix warn unused result on asprintf calls Date: Fri, 28 Apr 2023 14:21:34 +0200 Message-Id: <20230428122142.928135-8-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-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.2 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, 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" When enabling _FORTIFY_SOURCE, some functions now lead to warnings when their result is not checked. --- argp/argp-test.c | 8 +++++--- posix/tst-execl2.c | 8 ++------ posix/tst-execle2.c | 8 ++------ posix/tst-execlp2.c | 11 +++-------- 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(+), 53 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..8f10d4b7f8 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,8 +55,7 @@ do_test (void) return 1; } char *path; - asprintf (&path, "%s:../libio:../elf", bindir); - if (path == NULL) + if (asprintf (&path, "%s:../libio:../elf", bindir) < 0 || path == NULL) { puts ("asprintf failed"); return 1; 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 Fri Apr 28 12:21:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68485 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 DE7683899430 for ; Fri, 28 Apr 2023 12:40:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE7683899430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685618; bh=ADAnJToQnjr3VdzgPYPz5Y1F92rzdyzsNAdElFM2cbU=; 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=li4fatlTXE4d8CBVM5slb2PgP3nWa9TvHaaVMSx/h+aCjwivwdTFdC5wHO9egLJRc ODBJTE9cYkAKBLCFt48ZPG3L37aNwdGCSouzvFtR6W9Yuc9sIOH15dUCh9deScrCT+ 31QceibifpsTyv2dzSyNDiF76/JTH6KJsLmuey7o= 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 56DD93857016 for ; Fri, 28 Apr 2023 12:35:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 56DD93857016 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-283-XHjmL0AQOIuVo6pnIUiHrg-1; Fri, 28 Apr 2023 08:35:38 -0400 X-MC-Unique: XHjmL0AQOIuVo6pnIUiHrg-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 826843822DEB; Fri, 28 Apr 2023 12:35:28 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BCF55C15BA0; Fri, 28 Apr 2023 12:35:27 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 08/15] tests: replace write by xwrite Date: Fri, 28 Apr 2023 14:21:35 +0200 Message-Id: <20230428122142.928135-9-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-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.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, 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" Using write without cheks leads to warn unused result when __wur is enabled. Reviewed-by: Siddhesh Poyarekar --- dirent/tst-fdopendir.c | 4 +++- io/tst-faccessat.c | 3 ++- io/tst-fchmodat.c | 3 ++- io/tst-fchownat.c | 3 ++- io/tst-fstatat.c | 3 ++- io/tst-futimesat.c | 3 ++- io/tst-linkat.c | 3 ++- io/tst-openat.c | 3 ++- io/tst-renameat.c | 3 ++- io/tst-symlinkat.c | 3 ++- io/tst-unlinkat.c | 3 ++- libio/bug-ungetc.c | 4 +++- libio/bug-ungetc3.c | 4 +++- libio/bug-ungetc4.c | 4 +++- libio/bug-wfflush.c | 4 +++- libio/bug-wsetpos.c | 4 +++- nptl/tst-stackguard1.c | 4 +++- nptl/tst-tls3.c | 2 ++ nptl/tst-tls3mod.c | 5 +++-- rt/tst-cpuclock2.c | 4 +++- rt/tst-cputimer1.c | 4 +++- rt/tst-cputimer2.c | 4 +++- rt/tst-cputimer3.c | 4 +++- support/test-container.c | 8 ++++---- sysdeps/pthread/tst-cond18.c | 4 +++- sysdeps/pthread/tst-flock1.c | 3 ++- sysdeps/pthread/tst-flock2.c | 3 ++- sysdeps/pthread/tst-key1.c | 11 ++++++----- sysdeps/pthread/tst-signal1.c | 3 ++- sysdeps/pthread/tst-signal2.c | 3 ++- sysdeps/pthread/tst-timer.c | 3 ++- time/tst-cpuclock1.c | 4 +++- 32 files changed, 84 insertions(+), 39 deletions(-) diff --git a/dirent/tst-fdopendir.c b/dirent/tst-fdopendir.c index 6321af1daa..2c9520574d 100644 --- a/dirent/tst-fdopendir.c +++ b/dirent/tst-fdopendir.c @@ -7,6 +7,8 @@ #include #include +#include + #ifndef O_NOATIME # define O_NOATIME 0 #endif @@ -22,7 +24,7 @@ do_test (void) return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); close (fd); struct stat64 st; diff --git a/io/tst-faccessat.c b/io/tst-faccessat.c index 7bdeed008c..b90954e318 100644 --- a/io/tst-faccessat.c +++ b/io/tst-faccessat.c @@ -8,6 +8,7 @@ #include #include +#include static void prepare (void); #define PREPARE(argc, argv) prepare () @@ -96,7 +97,7 @@ do_test (void) puts ("file creation failed"); return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); puts ("file created"); /* Before closing the file, try using this file descriptor to open diff --git a/io/tst-fchmodat.c b/io/tst-fchmodat.c index 7d4a8717ff..83003e2f21 100644 --- a/io/tst-fchmodat.c +++ b/io/tst-fchmodat.c @@ -8,6 +8,7 @@ #include #include +#include static void prepare (void); #define PREPARE(argc, argv) prepare () @@ -98,7 +99,7 @@ do_test (void) puts ("file creation failed"); return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); puts ("file created"); struct stat64 st1; diff --git a/io/tst-fchownat.c b/io/tst-fchownat.c index e8adf6229f..c0b87cda8f 100644 --- a/io/tst-fchownat.c +++ b/io/tst-fchownat.c @@ -6,6 +6,7 @@ #include #include +#include static void prepare (void); #define PREPARE(argc, argv) prepare () @@ -106,7 +107,7 @@ do_test (void) puts ("file creation failed"); return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); puts ("file created"); struct stat64 st1; diff --git a/io/tst-fstatat.c b/io/tst-fstatat.c index 4766bb2e71..6a60024b63 100644 --- a/io/tst-fstatat.c +++ b/io/tst-fstatat.c @@ -6,6 +6,7 @@ #include #include +#include static void prepare (void); #define PREPARE(argc, argv) prepare () @@ -94,7 +95,7 @@ do_test (void) puts ("file creation failed"); return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); puts ("file created"); struct stat64 st1; diff --git a/io/tst-futimesat.c b/io/tst-futimesat.c index 3d41721f42..b7ef386e06 100644 --- a/io/tst-futimesat.c +++ b/io/tst-futimesat.c @@ -28,6 +28,7 @@ #include #include +#include #ifndef struct_stat # define struct_stat struct stat64 @@ -114,7 +115,7 @@ do_test (void) puts ("file creation failed"); return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); puts ("file created"); struct_stat st1; diff --git a/io/tst-linkat.c b/io/tst-linkat.c index 97445b7954..6b22a01c88 100644 --- a/io/tst-linkat.c +++ b/io/tst-linkat.c @@ -6,6 +6,7 @@ #include #include +#include static void prepare (void); #define PREPARE(argc, argv) prepare () @@ -94,7 +95,7 @@ do_test (void) puts ("file creation failed"); return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); puts ("file created"); struct stat64 st1; diff --git a/io/tst-openat.c b/io/tst-openat.c index 741b8d0ad2..2ce89e3db1 100644 --- a/io/tst-openat.c +++ b/io/tst-openat.c @@ -6,6 +6,7 @@ #include #include +#include static void prepare (void); #define PREPARE(argc, argv) prepare () @@ -94,7 +95,7 @@ do_test (void) puts ("file creation failed"); return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); /* Before closing the file, try using this file descriptor to open another file. This must fail. */ diff --git a/io/tst-renameat.c b/io/tst-renameat.c index 435302b52b..0b9da5fd6d 100644 --- a/io/tst-renameat.c +++ b/io/tst-renameat.c @@ -6,6 +6,7 @@ #include #include +#include static void prepare (void); #define PREPARE(argc, argv) prepare () @@ -94,7 +95,7 @@ do_test (void) puts ("file creation failed"); return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); puts ("file created"); struct stat64 st1; diff --git a/io/tst-symlinkat.c b/io/tst-symlinkat.c index 214a8e348e..4a34994df7 100644 --- a/io/tst-symlinkat.c +++ b/io/tst-symlinkat.c @@ -6,6 +6,7 @@ #include #include +#include static void prepare (void); #define PREPARE(argc, argv) prepare () @@ -94,7 +95,7 @@ do_test (void) puts ("file creation failed"); return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); puts ("file created"); struct stat64 st1; diff --git a/io/tst-unlinkat.c b/io/tst-unlinkat.c index e21d56f9f7..21a2dbaf57 100644 --- a/io/tst-unlinkat.c +++ b/io/tst-unlinkat.c @@ -6,6 +6,7 @@ #include #include +#include static void prepare (void); #define PREPARE(argc, argv) prepare () @@ -94,7 +95,7 @@ do_test (void) puts ("file creation failed"); return 1; } - write (fd, "hello", 5); + xwrite (fd, "hello", 5); close (fd); puts ("file created"); diff --git a/libio/bug-ungetc.c b/libio/bug-ungetc.c index 51940b68f5..4ea2d14ed6 100644 --- a/libio/bug-ungetc.c +++ b/libio/bug-ungetc.c @@ -2,6 +2,8 @@ #include +#include + static void do_prepare (void); #define PREPARE(argc, argv) do_prepare () static int do_test (void); @@ -20,7 +22,7 @@ do_prepare (void) printf ("cannot create temporary file: %m\n"); exit (1); } - write (fd, pattern, sizeof (pattern)); + xwrite (fd, pattern, sizeof (pattern)); close (fd); } diff --git a/libio/bug-ungetc3.c b/libio/bug-ungetc3.c index 0c83c1161e..6100d7a936 100644 --- a/libio/bug-ungetc3.c +++ b/libio/bug-ungetc3.c @@ -2,6 +2,8 @@ #include +#include + static void do_prepare (void); #define PREPARE(argc, argv) do_prepare () static int do_test (void); @@ -20,7 +22,7 @@ do_prepare (void) printf ("cannot create temporary file: %m\n"); exit (1); } - write (fd, pattern, sizeof (pattern)); + xwrite (fd, pattern, sizeof (pattern)); close (fd); } diff --git a/libio/bug-ungetc4.c b/libio/bug-ungetc4.c index 0bd02a570d..8a05def686 100644 --- a/libio/bug-ungetc4.c +++ b/libio/bug-ungetc4.c @@ -18,6 +18,8 @@ #include +#include + static void do_prepare (void); #define PREPARE(argc, argv) do_prepare () static int do_test (void); @@ -36,7 +38,7 @@ do_prepare (void) printf ("cannot create temporary file: %m\n"); exit (1); } - write (fd, pattern, sizeof (pattern) - 1); + xwrite (fd, pattern, sizeof (pattern) - 1); close (fd); } diff --git a/libio/bug-wfflush.c b/libio/bug-wfflush.c index a8fd61e997..d1b9d8e9de 100644 --- a/libio/bug-wfflush.c +++ b/libio/bug-wfflush.c @@ -3,6 +3,8 @@ #include #include +#include + static void do_prepare (void); #define PREPARE(argc, argv) do_prepare () static int do_test (void); @@ -20,7 +22,7 @@ do_prepare (void) printf ("cannot create temporary file: %m\n"); exit (1); } - write (fd, "1!", 2); + xwrite (fd, "1!", 2); close (fd); } diff --git a/libio/bug-wsetpos.c b/libio/bug-wsetpos.c index ccb22a4b62..0fc373ba49 100644 --- a/libio/bug-wsetpos.c +++ b/libio/bug-wsetpos.c @@ -4,6 +4,8 @@ #include #include +#include + static void do_prepare (void); #define PREPARE(argc, argv) do_prepare () static int do_test (void); @@ -22,7 +24,7 @@ do_prepare (void) printf ("cannot create temporary file: %m\n"); exit (1); } - write (fd, pattern, sizeof (pattern)); + xwrite (fd, pattern, sizeof (pattern)); close (fd); } diff --git a/nptl/tst-stackguard1.c b/nptl/tst-stackguard1.c index b9cf6844de..4ac57157e9 100644 --- a/nptl/tst-stackguard1.c +++ b/nptl/tst-stackguard1.c @@ -27,6 +27,8 @@ #include #include +#include + static const char *command; static bool child; static uintptr_t stack_chk_guard_copy; @@ -96,7 +98,7 @@ do_test (void) else if (ret != NULL) return 1; - write (2, &stack_chk_guard_copy, sizeof (stack_chk_guard_copy)); + xwrite (2, &stack_chk_guard_copy, sizeof (stack_chk_guard_copy)); return 0; } diff --git a/nptl/tst-tls3.c b/nptl/tst-tls3.c index b1a40c624a..33d94c8cc5 100644 --- a/nptl/tst-tls3.c +++ b/nptl/tst-tls3.c @@ -26,6 +26,8 @@ #include #include +#include + #define THE_SIG SIGUSR1 /* The stack size can be overriden. With a sufficiently large stack diff --git a/nptl/tst-tls3mod.c b/nptl/tst-tls3mod.c index c6e8910b1e..345a48e1c7 100644 --- a/nptl/tst-tls3mod.c +++ b/nptl/tst-tls3mod.c @@ -25,6 +25,7 @@ #include #include +#include extern pthread_barrier_t b; @@ -43,7 +44,7 @@ handler (int sig) { if (sig != THE_SIG) { - write (STDOUT_FILENO, "wrong signal\n", 13); + xwrite (STDOUT_FILENO, "wrong signal\n", 13); _exit (1); } @@ -51,7 +52,7 @@ handler (int sig) if (sem_post (&s) != 0) { - write (STDOUT_FILENO, "sem_post failed\n", 16); + xwrite (STDOUT_FILENO, "sem_post failed\n", 16); _exit (1); } } diff --git a/rt/tst-cpuclock2.c b/rt/tst-cpuclock2.c index e4584d8791..8afd34ed9c 100644 --- a/rt/tst-cpuclock2.c +++ b/rt/tst-cpuclock2.c @@ -37,6 +37,8 @@ do_test () #include #include +#include + static pthread_barrier_t barrier; /* This function is intended to rack up both user and system time. */ @@ -55,7 +57,7 @@ chew_cpu (void *arg) for (int i = 0; i < 100; ++i) for (size_t j = 0; j < sizeof buf; ++j) buf[j] = 0xbb; - write (nullfd, (char *) buf, sizeof buf); + xwrite (nullfd, (char *) buf, sizeof buf); close (nullfd); } diff --git a/rt/tst-cputimer1.c b/rt/tst-cputimer1.c index 8f5dd76cf2..18d8b195a2 100644 --- a/rt/tst-cputimer1.c +++ b/rt/tst-cputimer1.c @@ -11,6 +11,8 @@ #include #include +#include + #define TEST_CLOCK CLOCK_PROCESS_CPUTIME_ID #define TEST_CLOCK_MISSING(clock) \ (setup_test () ? "process CPU clock timer support" : NULL) @@ -29,7 +31,7 @@ chew_cpu (void *arg) for (int i = 0; i < 100; ++i) for (size_t j = 0; j < sizeof buf; ++j) buf[j] = 0xbb; - write (nullfd, (char *) buf, sizeof buf); + xwrite (nullfd, (char *) buf, sizeof buf); close (nullfd); } diff --git a/rt/tst-cputimer2.c b/rt/tst-cputimer2.c index 397d7998c0..a5700d4bac 100644 --- a/rt/tst-cputimer2.c +++ b/rt/tst-cputimer2.c @@ -12,6 +12,8 @@ #include #include +#include + static clockid_t worker_thread_clock; #define TEST_CLOCK worker_thread_clock @@ -32,7 +34,7 @@ chew_cpu (void *arg) for (int i = 0; i < 100; ++i) for (size_t j = 0; j < sizeof buf; ++j) buf[j] = 0xbb; - write (nullfd, (char *) buf, sizeof buf); + xwrite (nullfd, (char *) buf, sizeof buf); close (nullfd); } diff --git a/rt/tst-cputimer3.c b/rt/tst-cputimer3.c index 056766a377..786de93a02 100644 --- a/rt/tst-cputimer3.c +++ b/rt/tst-cputimer3.c @@ -13,6 +13,8 @@ #include #include +#include + static clockid_t child_clock; #define TEST_CLOCK child_clock @@ -33,7 +35,7 @@ chew_cpu (void) for (int i = 0; i < 100; ++i) for (size_t j = 0; j < sizeof buf; ++j) buf[j] = 0xbb; - write (nullfd, (char *) buf, sizeof buf); + xwrite (nullfd, (char *) buf, sizeof buf); close (nullfd); if (getppid () == 1) _exit (2); diff --git a/support/test-container.c b/support/test-container.c index e68f16eecf..d4ca41fe7c 100644 --- a/support/test-container.c +++ b/support/test-container.c @@ -1186,7 +1186,7 @@ main (int argc, char **argv) int status; /* Send the child's "outside" pid to it. */ - write (pipes[1], &child, sizeof(child)); + xwrite (pipes[1], &child, sizeof(child)); close (pipes[0]); close (pipes[1]); @@ -1255,7 +1255,7 @@ main (int argc, char **argv) sprintf (tmp, "%lld %lld 1\n", (long long) (be_su ? 0 : original_uid), (long long) original_uid); - write (UMAP, tmp, strlen (tmp)); + xwrite (UMAP, tmp, strlen (tmp)); xclose (UMAP); /* We must disable setgroups () before we can map our groups, else we @@ -1264,7 +1264,7 @@ main (int argc, char **argv) if (GMAP >= 0) { /* We support kernels old enough to not have this. */ - write (GMAP, "deny\n", 5); + xwrite (GMAP, "deny\n", 5); xclose (GMAP); } @@ -1276,7 +1276,7 @@ main (int argc, char **argv) sprintf (tmp, "%lld %lld 1\n", (long long) (be_su ? 0 : original_gid), (long long) original_gid); - write (GMAP, tmp, strlen (tmp)); + xwrite (GMAP, tmp, strlen (tmp)); xclose (GMAP); } diff --git a/sysdeps/pthread/tst-cond18.c b/sysdeps/pthread/tst-cond18.c index edac4fa4ff..ffae356c04 100644 --- a/sysdeps/pthread/tst-cond18.c +++ b/sysdeps/pthread/tst-cond18.c @@ -24,6 +24,8 @@ #include #include +#include + pthread_cond_t cv = PTHREAD_COND_INITIALIZER; pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; bool exiting; @@ -40,7 +42,7 @@ tf (void *id) while (!exiting) { if ((spins++ % 1000) == 0) - write (fd, ".", 1); + xwrite (fd, ".", 1); pthread_mutex_unlock (&lock); pthread_mutex_lock (&lock); diff --git a/sysdeps/pthread/tst-flock1.c b/sysdeps/pthread/tst-flock1.c index 7eef9070ab..9de148afd3 100644 --- a/sysdeps/pthread/tst-flock1.c +++ b/sysdeps/pthread/tst-flock1.c @@ -21,6 +21,7 @@ #include #include +#include static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; @@ -56,7 +57,7 @@ do_test (void) unlink (tmp); - write (fd, "foobar xyzzy", 12); + xwrite (fd, "foobar xyzzy", 12); if (flock (fd, LOCK_EX | LOCK_NB) != 0) { diff --git a/sysdeps/pthread/tst-flock2.c b/sysdeps/pthread/tst-flock2.c index 8762e93b52..952b79e5db 100644 --- a/sysdeps/pthread/tst-flock2.c +++ b/sysdeps/pthread/tst-flock2.c @@ -24,6 +24,7 @@ #include #include +#include static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER; @@ -70,7 +71,7 @@ do_test (void) int i; for (i = 0; i < 20; ++i) - write (fd, "foobar xyzzy", 12); + xwrite (fd, "foobar xyzzy", 12); pthread_barrier_t *b; b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE, diff --git a/sysdeps/pthread/tst-key1.c b/sysdeps/pthread/tst-key1.c index 933edafef8..60245c4e47 100644 --- a/sysdeps/pthread/tst-key1.c +++ b/sysdeps/pthread/tst-key1.c @@ -21,6 +21,7 @@ #include #include +#include static int do_test (void); @@ -51,7 +52,7 @@ do_test (void) if (pthread_setspecific (keys[i], (const void *) (i + 100l)) != 0) { - write (2, "setspecific failed\n", 19); + xwrite (2, "setspecific failed\n", 19); _exit (1); } } @@ -60,13 +61,13 @@ do_test (void) { if (pthread_getspecific (keys[i]) != (void *) (i + 100l)) { - write (2, "getspecific failed\n", 19); + xwrite (2, "getspecific failed\n", 19); _exit (1); } if (pthread_key_delete (keys[i]) != 0) { - write (2, "key_delete failed\n", 18); + xwrite (2, "key_delete failed\n", 18); _exit (1); } } @@ -74,13 +75,13 @@ do_test (void) /* Now it must be once again possible to allocate keys. */ if (pthread_key_create (&keys[0], NULL) != 0) { - write (2, "2nd key_create failed\n", 22); + xwrite (2, "2nd key_create failed\n", 22); _exit (1); } if (pthread_key_delete (keys[0]) != 0) { - write (2, "2nd key_delete failed\n", 22); + xwrite (2, "2nd key_delete failed\n", 22); _exit (1); } diff --git a/sysdeps/pthread/tst-signal1.c b/sysdeps/pthread/tst-signal1.c index d1073e8459..d1082027ca 100644 --- a/sysdeps/pthread/tst-signal1.c +++ b/sysdeps/pthread/tst-signal1.c @@ -25,6 +25,7 @@ #include #include +#include static sigset_t ss; static pthread_barrier_t *b; @@ -105,7 +106,7 @@ do_test (void) int i; for (i = 0; i < 20; ++i) - write (fd, "foobar xyzzy", 12); + xwrite (fd, "foobar xyzzy", 12); b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); diff --git a/sysdeps/pthread/tst-signal2.c b/sysdeps/pthread/tst-signal2.c index dfe7d9f64a..15b7747877 100644 --- a/sysdeps/pthread/tst-signal2.c +++ b/sysdeps/pthread/tst-signal2.c @@ -25,6 +25,7 @@ #include #include +#include static sigset_t ss; static pthread_barrier_t *b; @@ -111,7 +112,7 @@ do_test (void) int i; for (i = 0; i < 20; ++i) - write (fd, "foobar xyzzy", 12); + xwrite (fd, "foobar xyzzy", 12); b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); diff --git a/sysdeps/pthread/tst-timer.c b/sysdeps/pthread/tst-timer.c index 47472ab8e1..4cfe0b67dc 100644 --- a/sysdeps/pthread/tst-timer.c +++ b/sysdeps/pthread/tst-timer.c @@ -24,6 +24,7 @@ #include #include +#include static void notify_func1 (union sigval sigval) @@ -44,7 +45,7 @@ signal_func (int sig) { static const char text[] = "signal_func\n"; signal (sig, signal_func); - write (STDOUT_FILENO, text, sizeof text - 1); + xwrite (STDOUT_FILENO, text, sizeof text - 1); } static void diff --git a/time/tst-cpuclock1.c b/time/tst-cpuclock1.c index 6f2e70a58a..6a793e06df 100644 --- a/time/tst-cpuclock1.c +++ b/time/tst-cpuclock1.c @@ -27,6 +27,8 @@ #include #include +#include + /* This function is intended to rack up both user and system time. */ static void chew_cpu (void) @@ -41,7 +43,7 @@ chew_cpu (void) for (int i = 0; i < 100; ++i) for (size_t j = 0; j < sizeof buf; ++j) buf[j] = 0xbb; - write (nullfd, (char *) buf, sizeof buf); + xwrite (nullfd, (char *) buf, sizeof buf); close (nullfd); if (getppid () == 1) _exit (2); From patchwork Fri Apr 28 12:21:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68472 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 F31CD3854166 for ; Fri, 28 Apr 2023 12:36:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F31CD3854166 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685404; bh=xavweRnntNn31wTgk/cM/Dtjp14reEFIusBXJY369LM=; 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=UpeAdzAUjWaagkpUcLk198qEOiazpSRfT5QwXr3SFIDX2P7FHOTYW5oNYfXNbxBTE oO15C520uYDaBsbWmMaKpOhC7wPOeeTos3gzO1uO0sksfLQ0ZadU6N+mbXPuW6VhAS qNE2bo4NTZQ+eo9CaYSVu8ZEmxpS1dBoRexNPpCk= 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 E960C385771F for ; Fri, 28 Apr 2023 12:35:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E960C385771F 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-410-FwkRusbZNSehDZdY5E3stA-1; Fri, 28 Apr 2023 08:35:29 -0400 X-MC-Unique: FwkRusbZNSehDZdY5E3stA-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 69AB43C025C5; Fri, 28 Apr 2023 12:35:29 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BFA57C15BA0; Fri, 28 Apr 2023 12:35:28 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 09/15] tests: replace read by xread Date: Fri, 28 Apr 2023 14:21:36 +0200 Message-Id: <20230428122142.928135-10-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-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.5 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, 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" Changes since v2: - Add missing xunistd.h includes - Add libsupport to tst-fini1mod.so --8<-- With fortification enabled, read calls return result needs to be checked, has it gets the __wur macro enabled. --- dirent/tst-fdopendir.c | 3 ++- nptl/tst-cleanup4.c | 4 +++- support/Makefile | 1 + support/test-container.c | 3 ++- support/xread.c | 36 ++++++++++++++++++++++++++++++++++ support/xunistd.h | 3 +++ sysdeps/pthread/Makefile | 2 +- sysdeps/pthread/tst-cancel11.c | 4 +++- sysdeps/pthread/tst-cancel20.c | 10 +++------- sysdeps/pthread/tst-cancel21.c | 9 ++------- sysdeps/pthread/tst-fini1mod.c | 4 +++- 11 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 support/xread.c diff --git a/dirent/tst-fdopendir.c b/dirent/tst-fdopendir.c index 2c9520574d..d6a24f47db 100644 --- a/dirent/tst-fdopendir.c +++ b/dirent/tst-fdopendir.c @@ -45,7 +45,8 @@ do_test (void) } char buf[5]; - read(fd, buf, sizeof (buf)); + xread(fd, buf, sizeof (buf)); + close(fd); struct stat64 st2; diff --git a/nptl/tst-cleanup4.c b/nptl/tst-cleanup4.c index 1d3d53fb5f..f2e9f263e5 100644 --- a/nptl/tst-cleanup4.c +++ b/nptl/tst-cleanup4.c @@ -21,6 +21,8 @@ #include #include +#include + /* LinuxThreads pthread_cleanup_{push,pop} helpers. */ extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer, void (*__routine) (void *), @@ -64,7 +66,7 @@ fn_read (void) } char c; - read (fds[0], &c, 1); + xread (fds[0], &c, 1); } diff --git a/support/Makefile b/support/Makefile index 71d5148513..a4ac86544c 100644 --- a/support/Makefile +++ b/support/Makefile @@ -193,6 +193,7 @@ libsupport-routines = \ xpthread_spin_unlock \ xraise \ xreadlink \ + xread \ xrealloc \ xrecvfrom \ xsendto \ diff --git a/support/test-container.c b/support/test-container.c index d4ca41fe7c..37beb778d6 100644 --- a/support/test-container.c +++ b/support/test-container.c @@ -1217,7 +1217,8 @@ main (int argc, char **argv) /* Get our "outside" pid from our parent. We use this to help with debugging from outside the container. */ - read (pipes[0], &child, sizeof(child)); + xread (pipes[0], &child, sizeof(child)); + close (pipes[0]); close (pipes[1]); sprintf (pid_buf, "%lu", (long unsigned)child); diff --git a/support/xread.c b/support/xread.c new file mode 100644 index 0000000000..215f9b4f00 --- /dev/null +++ b/support/xread.c @@ -0,0 +1,36 @@ +/* read with error checking and retries. + 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 + . */ + +#include + +#include + +void +xread (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) + FAIL_EXIT1 ("read of %zu bytes failed after %td: %m", + length, p - (char *) buffer); + p += ret; + } +} diff --git a/support/xunistd.h b/support/xunistd.h index 43a1e69fcb..0aa2638a8d 100644 --- a/support/xunistd.h +++ b/support/xunistd.h @@ -77,6 +77,9 @@ void xclose (int); /* Write the buffer. Retry on short writes. */ void xwrite (int, const void *, size_t); +/* Read to buffer. Retry on short reads. */ +void xread (int, void *, size_t); + /* Invoke mmap with a zero file offset. */ void *xmmap (void *addr, size_t length, int prot, int flags, int fd); void xmprotect (void *addr, size_t length, int prot); diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile index c2f5588bd9..86d41a8c88 100644 --- a/sysdeps/pthread/Makefile +++ b/sysdeps/pthread/Makefile @@ -275,7 +275,7 @@ $(objpfx)tst-cancel28: $(librt) $(objpfx)tst-fini1: $(shared-thread-library) $(objpfx)tst-fini1mod.so -$(objpfx)tst-fini1mod.so: $(shared-thread-library) +$(objpfx)tst-fini1mod.so: $(libsupport) $(shared-thread-library) $(objpfx)tst-_res1mod2.so: $(objpfx)tst-_res1mod1.so LDFLAGS-tst-_res1mod1.so = -Wl,-soname,tst-_res1mod1.so diff --git a/sysdeps/pthread/tst-cancel11.c b/sysdeps/pthread/tst-cancel11.c index 4dd84d6673..449f3b9b63 100644 --- a/sysdeps/pthread/tst-cancel11.c +++ b/sysdeps/pthread/tst-cancel11.c @@ -22,6 +22,8 @@ #include #include +#include + static pthread_barrier_t bar; static int fd[2]; @@ -56,7 +58,7 @@ tf (void *arg) /* This call should block and be cancelable. */ char buf[20]; - read (fd[0], buf, sizeof (buf)); + xread (fd[0], buf, sizeof (buf)); pthread_cleanup_pop (0); diff --git a/sysdeps/pthread/tst-cancel20.c b/sysdeps/pthread/tst-cancel20.c index 1d5c53049b..0f1ada3742 100644 --- a/sysdeps/pthread/tst-cancel20.c +++ b/sysdeps/pthread/tst-cancel20.c @@ -22,6 +22,8 @@ #include #include +#include + static int fd[4]; static pthread_barrier_t b; @@ -43,11 +45,7 @@ sh_body (void) pthread_cleanup_push (cl, (void *) 1L); in_sh_body = 1; - if (read (fd[2], &c, 1) == 1) - { - puts ("read succeeded"); - exit (1); - } + xread (fd[2], &c, 1); pthread_cleanup_pop (0); } @@ -84,8 +82,6 @@ tf_body (void) exit (1); } - read (fd[0], &c, 1); - pthread_cleanup_pop (0); } diff --git a/sysdeps/pthread/tst-cancel21.c b/sysdeps/pthread/tst-cancel21.c index bc4ff308f9..c14ed37d14 100644 --- a/sysdeps/pthread/tst-cancel21.c +++ b/sysdeps/pthread/tst-cancel21.c @@ -23,6 +23,7 @@ #include #include +#include static int fd[4]; static pthread_barrier_t b; @@ -44,11 +45,7 @@ sh_body (void) pthread_cleanup_push (cl, (void *) 1L); in_sh_body = 1; - if (read (fd[2], &c, 1) == 1) - { - puts ("read succeeded"); - exit (1); - } + xread (fd[2], &c, 1); pthread_cleanup_pop (0); } @@ -85,8 +82,6 @@ tf_body (void) exit (1); } - read (fd[0], &c, 1); - pthread_cleanup_pop (0); } diff --git a/sysdeps/pthread/tst-fini1mod.c b/sysdeps/pthread/tst-fini1mod.c index cdadf034cd..0a45f6c5f2 100644 --- a/sysdeps/pthread/tst-fini1mod.c +++ b/sysdeps/pthread/tst-fini1mod.c @@ -20,6 +20,8 @@ #include #include +#include + static void * tf (void *arg) @@ -32,7 +34,7 @@ tf (void *arg) } char buf[10]; - read (fds[0], buf, sizeof (buf)); + xread (fds[0], buf, sizeof (buf)); puts ("read returned"); exit (1); From patchwork Fri Apr 28 12:21:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68474 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 EEDF538708FA for ; Fri, 28 Apr 2023 12:36:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEDF538708FA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685418; bh=51OOAB1NWV+8WN3dTvAoULmdRfXGEjbNVe/WFVmQ2aI=; 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=KL6Kb1xNdvyUoTlzdrT9/SHdmc03lwSwTfflDeQDefZiOF2U7cvlz8sA1bQa1fzU2 1sv4IUQRhXGKg8Cibsz9UhUgWJfkqlIslRwFIFmIUu+78u+LU3c+/cOH+4m+nbYRRp Y9tmHExQWGouT8HnD1OTqpyFcQgMchq0THU0spAY= 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 6DB86385771A for ; Fri, 28 Apr 2023 12:35:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6DB86385771A 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-221-R8VnLg26MiOFm241svd19w-1; Fri, 28 Apr 2023 08:35:30 -0400 X-MC-Unique: R8VnLg26MiOFm241svd19w-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 4D6EC887400; Fri, 28 Apr 2023 12:35:30 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A574CC15BA0; Fri, 28 Apr 2023 12:35:29 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 10/15] tests: replace system by xsystem Date: Fri, 28 Apr 2023 14:21:37 +0200 Message-Id: <20230428122142.928135-11-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-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.2 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, 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" With fortification enabled, system calls return result needs to be checked, has it gets the __wur macro enabled. --- elf/tst-stackguard1.c | 2 +- libio/bug-mmap-fflush.c | 7 +++++-- nptl/tst-cancel7.c | 3 ++- nptl/tst-stackguard1.c | 2 +- nss/tst-nss-db-endpwent.c | 3 ++- support/Makefile | 1 + support/xstdlib.h | 31 +++++++++++++++++++++++++++++++ support/xsystem.c | 29 +++++++++++++++++++++++++++++ 8 files changed, 72 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..7dbde6568c 100644 --- a/elf/tst-stackguard1.c +++ b/elf/tst-stackguard1.c @@ -108,7 +108,7 @@ do_test (void) dup2 (fds[1], 2); close (fds[1]); - system (command); + if (system (command)) {/* We aren't interested on the result */} 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..9ec9e8f982 100644 --- a/nptl/tst-stackguard1.c +++ b/nptl/tst-stackguard1.c @@ -140,7 +140,7 @@ do_test (void) dup2 (fds[1], 2); close (fds[1]); - system (command); + if (system (command)) {/* We aren't interested in the result */} 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 a4ac86544c..4c8eb3dedd 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..8ceaad1531 --- /dev/null +++ b/support/xsystem.c @@ -0,0 +1,29 @@ +/* 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) +{ + if (system (cmd) < 0) + FAIL_EXIT1 ("system (\"%s\")", cmd); +} From patchwork Fri Apr 28 12:21:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68478 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 3D5523853549 for ; Fri, 28 Apr 2023 12:37:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D5523853549 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685466; bh=pJMvy+CN5N5h90iDsGg7WMcloPp2AtVF1aPn/R7SYVA=; 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=SgwOmIYcPsUp20ZdAwch6Hf6Y4h2mDTwK2gPbVvDyf/qQpel3URd4GshLQDsADTTL 9kJdGKBPtrygjVf1wEyGWw54u2qATCpoH5ez8kS9E08rasYRKr7+reXosIK+7rHc1C J7WpBLOmqmOnS7jFJu9nIIvX2+jvY0pvOcHZMWyE= 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 DA78F3857720 for ; Fri, 28 Apr 2023 12:35:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA78F3857720 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-584-_NYKQ_BxNDqRSuVgdCdVTw-1; Fri, 28 Apr 2023 08:35:31 -0400 X-MC-Unique: _NYKQ_BxNDqRSuVgdCdVTw-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 32BB7101A531; Fri, 28 Apr 2023 12:35:31 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89A25C15BA0; Fri, 28 Apr 2023 12:35:30 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 11/15] tests: replace fread by xfread Date: Fri, 28 Apr 2023 14:21:38 +0200 Message-Id: <20230428122142.928135-12-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-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.2 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, 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" Changes since v2: - Fixed xfread prototype - Add missing xstdio.h include --8<-- With fortification enabled, fread calls return result needs to be checked, has it gets the __wur macro enabled. --- libio/bug-fseek.c | 7 ++++--- stdio-common/bug12.c | 12 ++++++----- stdio-common/bug3.c | 4 +++- stdio-common/bug4.c | 4 +++- stdio-common/tst-cookie.c | 5 ++++- stdio-common/tst-fmemopen3.c | 4 +++- support/Makefile | 1 + support/xfread.c | 39 ++++++++++++++++++++++++++++++++++++ support/xstdio.h | 1 + 9 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 support/xfread.c diff --git a/libio/bug-fseek.c b/libio/bug-fseek.c index 1b60580b53..19d5e2429e 100644 --- a/libio/bug-fseek.c +++ b/libio/bug-fseek.c @@ -3,6 +3,7 @@ #include #include +#include static char *fname; @@ -48,7 +49,7 @@ do_test (void) perror ("fopen(\"r\")"); } - fread (buf, 3, 1, f); + xfread (buf, 3, 1, f); errno = 0; if (fseek (f, -10, SEEK_CUR) == 0) { @@ -72,7 +73,7 @@ Got %d instead\n", perror ("fopen(\"r+\")"); } - fread (buf, 3, 1, f); + xfread (buf, 3, 1, f); errno = 0; if (fseek (f, -10, SEEK_CUR) == 0) { @@ -96,7 +97,7 @@ Got %d instead\n", perror ("fopen(\"r+\")"); } - fread (buf, 3, 1, f); + xfread (buf, 3, 1, f); if (ftell (f) != 3) { puts ("ftell failed"); diff --git a/stdio-common/bug12.c b/stdio-common/bug12.c index 48610c0e78..1ba296deb4 100644 --- a/stdio-common/bug12.c +++ b/stdio-common/bug12.c @@ -1,6 +1,8 @@ #include #include +#include + char x[4096], z[4096], b[21], m[4096 * 4]; int @@ -20,24 +22,24 @@ main (void) } rewind (f); - fread (m, 4096 * 4 - 10, 1, f); - fread (b, 20, 1, f); + xfread (m, 4096 * 4 - 10, 1, f); + xfread (b, 20, 1, f); printf ("got %s (should be %s)\n", b, "zzzzzzzzzzxxxxxxxxxx"); if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx")) failed = 1; fseek (f, -40, SEEK_CUR); - fread (b, 20, 1, f); + xfread (b, 20, 1, f); printf ("got %s (should be %s)\n", b, "zzzzzzzzzzzzzzzzzzzz"); if (strcmp (b, "zzzzzzzzzzzzzzzzzzzz")) failed = 1; - fread (b, 20, 1, f); + xfread (b, 20, 1, f); printf ("got %s (should be %s)\n", b, "zzzzzzzzzzxxxxxxxxxx"); if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx")) failed = 1; - fread (b, 20, 1, f); + xfread (b, 20, 1, f); printf ("got %s (should be %s)\n", b, "xxxxxxxxxxxxxxxxxxxx"); if (strcmp (b, "xxxxxxxxxxxxxxxxxxxx")) failed = 1; diff --git a/stdio-common/bug3.c b/stdio-common/bug3.c index 62a6cab330..deabd00572 100644 --- a/stdio-common/bug3.c +++ b/stdio-common/bug3.c @@ -1,6 +1,8 @@ #include #include +#include + int main (void) { @@ -32,7 +34,7 @@ main (void) char buf[25]; buf[0] = j; - fread (buf + 1, 1, 23, f); + xfread (buf + 1, 1, 23, f); buf[24] = '\0'; if (strcmp (buf, "Where does this text go?") != 0) { diff --git a/stdio-common/bug4.c b/stdio-common/bug4.c index cf7fe116eb..4059ff75b3 100644 --- a/stdio-common/bug4.c +++ b/stdio-common/bug4.c @@ -2,6 +2,8 @@ #include #include +#include + int stdio_block_read = 1, stdio_block_write = 1; int @@ -30,7 +32,7 @@ main (int argc, char *argv[]) fseek (f, 8180L, 0); fwrite ("Where does this text come from?", 1, 31, f); fseek (f, 8180L, 0); - fread (buffer, 1, 31, f); + xfread (buffer, 1, 31, f); fwrite (buffer, 1, 31, stdout); fclose (f); remove (filename); diff --git a/stdio-common/tst-cookie.c b/stdio-common/tst-cookie.c index 030e684562..90ebc8e58c 100644 --- a/stdio-common/tst-cookie.c +++ b/stdio-common/tst-cookie.c @@ -5,6 +5,8 @@ #include +#include + #define THE_COOKIE ((void *) 0xdeadbeeful) @@ -77,7 +79,8 @@ do_test (void) f = fopencookie (THE_COOKIE, "r+", fcts); - fread (buf, 1, 1, f); + xfread (buf, 1, 1, f); + fwrite (buf, 1, 1, f); fseek (f, 0, SEEK_CUR); fclose (f); diff --git a/stdio-common/tst-fmemopen3.c b/stdio-common/tst-fmemopen3.c index 3cc2832edc..9297e24ba5 100644 --- a/stdio-common/tst-fmemopen3.c +++ b/stdio-common/tst-fmemopen3.c @@ -21,6 +21,8 @@ #include #include +#include + static void print_buffer (const char *s, size_t n) { @@ -153,7 +155,7 @@ do_test_read_seek_neg (const char *mode, const char *expected) FILE *fp = fmemopen (buf, sizeof (buf), mode); fseek (fp, offset, SEEK_END); - fread (tmp, tmps, 1, fp); + xfread (tmp, tmps, 1, fp); if (memcmp (tmp, expected, tmps) != 0) { diff --git a/support/Makefile b/support/Makefile index 4c8eb3dedd..c9b3364810 100644 --- a/support/Makefile +++ b/support/Makefile @@ -126,6 +126,7 @@ libsupport-routines = \ xfopen \ xfork \ xfreopen \ + xfread \ xftruncate \ xgetline \ xgetsockname \ diff --git a/support/xfread.c b/support/xfread.c new file mode 100644 index 0000000000..c21187d476 --- /dev/null +++ b/support/xfread.c @@ -0,0 +1,39 @@ +/* fread with error checking. + 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 + . */ + +#include + +#include +#include + +void +xfread (void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + size_t count = 0; + char *p = ptr; + + while (count < nmemb) + { + size_t ret = fread (p, size, nmemb - count, stream); + if (ret <= 0 && ferror(stream)) + FAIL_EXIT1 ("read of %zu bytes failed after %td: %m", + size * nmemb, p - (char *) ptr); + count += ret; + p += size * ret; + } +} diff --git a/support/xstdio.h b/support/xstdio.h index 5410d42579..633c342c82 100644 --- a/support/xstdio.h +++ b/support/xstdio.h @@ -27,6 +27,7 @@ __BEGIN_DECLS FILE *xfopen (const char *path, const char *mode); void xfclose (FILE *); FILE *xfreopen (const char *path, const char *mode, FILE *stream); +void xfread (void *ptr, size_t size, size_t nmemb, FILE *stream); /* Read a line from FP, using getline. *BUFFER must be NULL, or a heap-allocated pointer of *LENGTH bytes. Return the number of From patchwork Fri Apr 28 12:21:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68483 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 2D22A385276B for ; Fri, 28 Apr 2023 12:39:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D22A385276B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685545; bh=TF7S/xOt66PQ1MlirXA3lXPBNPbrD+GAX6jfAQnI2RM=; 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=iiiE8S7CDKxj/HJllhnwfmrs0bxQmcniOzgjur5w1jBjreCV7dpFLtah4s96wenbv sM+mLww0k8RyRifPOmZXfE4OXbiFlXThyv96o1m14zrQ87jkJD6tOfb1UUiGbHu6oN 9PwKXcvJsr23jIO10JZlz/T2I7DCLj7Ki6A8ZJkA= 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 1AF333857341 for ; Fri, 28 Apr 2023 12:35:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1AF333857341 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-84-sJmDmDyOOrqqxBYUz5FLuw-1; Fri, 28 Apr 2023 08:35:32 -0400 X-MC-Unique: sJmDmDyOOrqqxBYUz5FLuw-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 1CBB2280A330; Fri, 28 Apr 2023 12:35:32 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6DF01C15BA0; Fri, 28 Apr 2023 12:35:31 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 12/15] tests: replace ftruncate by xftruncate Date: Fri, 28 Apr 2023 14:21:39 +0200 Message-Id: <20230428122142.928135-13-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-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.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, 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" With fortification enabled, ftruncate calls return result needs to be checked, has it gets the __wur macro enabled. Reviewed-by: Siddhesh Poyarekar --- io/tst-copy_file_range.c | 2 +- posix/tst-getopt-cancel.c | 3 ++- stdio-common/tst-perror.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/io/tst-copy_file_range.c b/io/tst-copy_file_range.c index d1f3aaa5a9..bd64e9c42b 100644 --- a/io/tst-copy_file_range.c +++ b/io/tst-copy_file_range.c @@ -166,7 +166,7 @@ short_copy (void) inoff = 3; xlseek (infd, shift, SEEK_SET); } - ftruncate (outfd, 0); + xftruncate (outfd, 0); xlseek (outfd, 0, SEEK_SET); outoff = 0; diff --git a/posix/tst-getopt-cancel.c b/posix/tst-getopt-cancel.c index 7167d1a914..6f49391690 100644 --- a/posix/tst-getopt-cancel.c +++ b/posix/tst-getopt-cancel.c @@ -33,6 +33,7 @@ #include #include #include +#include static bool check_stderr (bool expect_errmsg, FILE *stderr_trapped) @@ -48,7 +49,7 @@ check_stderr (bool expect_errmsg, FILE *stderr_trapped) fputs (lineptr, stdout); } rewind (stderr_trapped); - ftruncate (fileno (stderr_trapped), 0); + xftruncate (fileno (stderr_trapped), 0); return got_errmsg == expect_errmsg; } diff --git a/stdio-common/tst-perror.c b/stdio-common/tst-perror.c index 57835e0c59..b4ab583462 100644 --- a/stdio-common/tst-perror.c +++ b/stdio-common/tst-perror.c @@ -9,6 +9,7 @@ #include #include +#include #define MB_EXP \ "null mode test 1: Invalid or incomplete multibyte or wide character\n" \ @@ -94,7 +95,7 @@ do_test (void) puts ("multibyte test succeeded"); lseek (fd, 0, SEEK_SET); - ftruncate (fd, 0); + xftruncate (fd, 0); if (dup2 (fd, 2) == -1) { From patchwork Fri Apr 28 12:21:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68482 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 3A17E3888C7A for ; Fri, 28 Apr 2023 12:38:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A17E3888C7A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685514; bh=8jAt6vST54zaWMOZOB4y83S/EfiPD6le/OSrrpcwmkQ=; 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=ie7xOFb2zvm1F3FCbzRHlB1hQOM/3nF0slGmuoy7Y6UQXJJDqL/iDk9yVEjbZ/2WF ILMDDL6h4DdtPmoX91LS6nmg+oKAohZf0l7LgInytJC0Ulik7zNgaLnELGuSlX6A0P Roz5YRFRCD1PEIvMjM7iguUpCorxRQVN7jAbiaV0= 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 C820F3858002 for ; Fri, 28 Apr 2023 12:35:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C820F3858002 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-634-Eq6k-9UsNs2LtCdNYfi-oA-1; Fri, 28 Apr 2023 08:35:33 -0400 X-MC-Unique: Eq6k-9UsNs2LtCdNYfi-oA-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 03E8A1078504; Fri, 28 Apr 2023 12:35:33 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59601C15BA0; Fri, 28 Apr 2023 12:35:32 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 13/15] tests: replace fgets by xfgets Date: Fri, 28 Apr 2023 14:21:40 +0200 Message-Id: <20230428122142.928135-14-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-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, KAM_SHORT, 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" Changes since v2: - Rebased --8<-- With fortification enabled, fgets calls return result needs to be checked, has it gets the __wur macro enabled. --- assert/test-assert-perr.c | 8 +++++--- assert/test-assert.c | 8 +++++--- stdio-common/test_rdwr.c | 11 ++++------- support/Makefile | 1 + support/xfgets.c | 32 ++++++++++++++++++++++++++++++++ support/xstdio.h | 1 + sysdeps/pthread/tst-cancel6.c | 3 ++- 7 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 support/xfgets.c diff --git a/assert/test-assert-perr.c b/assert/test-assert-perr.c index 8496db6ffd..09a4fcb6ef 100644 --- a/assert/test-assert-perr.c +++ b/assert/test-assert-perr.c @@ -11,6 +11,8 @@ #include #include +#include + jmp_buf rec; char buf[160]; @@ -70,15 +72,15 @@ main(void) failed = 1; /* should not happen */ rewind (stderr); - fgets (buf, 160, stderr); + xfgets (buf, 160, stderr); if (!strstr(buf, strerror (1))) failed = 1; - fgets (buf, 160, stderr); + xfgets (buf, 160, stderr); if (strstr (buf, strerror (0))) failed = 1; - fgets (buf, 160, stderr); + xfgets (buf, 160, stderr); if (strstr (buf, strerror (2))) failed = 1; diff --git a/assert/test-assert.c b/assert/test-assert.c index 26b58d4dd3..25e264543b 100644 --- a/assert/test-assert.c +++ b/assert/test-assert.c @@ -11,6 +11,8 @@ #include #include +#include + jmp_buf rec; char buf[160]; @@ -72,15 +74,15 @@ main (void) failed = 1; /* should not happen */ rewind (stderr); - fgets (buf, 160, stderr); + xfgets (buf, 160, stderr); if (!strstr (buf, "1 == 2")) failed = 1; - fgets (buf, 160, stderr); + xfgets (buf, 160, stderr); if (strstr (buf, "1 == 1")) failed = 1; - fgets (buf, 160, stderr); + xfgets (buf, 160, stderr); if (strstr (buf, "2 == 3")) failed = 1; diff --git a/stdio-common/test_rdwr.c b/stdio-common/test_rdwr.c index 7825ca9358..0544916eb1 100644 --- a/stdio-common/test_rdwr.c +++ b/stdio-common/test_rdwr.c @@ -20,6 +20,7 @@ #include #include +#include int main (int argc, char **argv) @@ -49,7 +50,7 @@ main (int argc, char **argv) (void) fputs (hello, f); rewind (f); - (void) fgets (buf, sizeof (buf), f); + xfgets (buf, sizeof (buf), f); rewind (f); (void) fputs (buf, f); rewind (f); @@ -104,12 +105,8 @@ main (int argc, char **argv) if (!lose) { rewind (f); - if (fgets (buf, sizeof (buf), f) == NULL) - { - printf ("fgets got %s.\n", strerror(errno)); - lose = 1; - } - else if (strcmp (buf, replace)) + xfgets (buf, sizeof (buf), f); + if (strcmp (buf, replace)) { printf ("Read \"%s\" instead of \"%s\".\n", buf, replace); lose = 1; diff --git a/support/Makefile b/support/Makefile index c9b3364810..344e63e74e 100644 --- a/support/Makefile +++ b/support/Makefile @@ -123,6 +123,7 @@ libsupport-routines = \ xdup2 \ xfchmod \ xfclose \ + xfgets \ xfopen \ xfork \ xfreopen \ diff --git a/support/xfgets.c b/support/xfgets.c new file mode 100644 index 0000000000..e2db19cf53 --- /dev/null +++ b/support/xfgets.c @@ -0,0 +1,32 @@ +/* fgets with error checking. + 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 + . */ + +#include + +#include +#include + +char * +xfgets (char *s, int size, FILE *stream) +{ + char *ret = fgets (s, size, stream); + if (!ret && ferror(stream)) + FAIL_EXIT1 ("fgets failed: %m"); + + return ret; +} diff --git a/support/xstdio.h b/support/xstdio.h index 633c342c82..f30bee6a20 100644 --- a/support/xstdio.h +++ b/support/xstdio.h @@ -28,6 +28,7 @@ FILE *xfopen (const char *path, const char *mode); void xfclose (FILE *); FILE *xfreopen (const char *path, const char *mode, FILE *stream); void xfread (void *ptr, size_t size, size_t nmemb, FILE *stream); +char *xfgets (char *s, int size, FILE *stream); /* Read a line from FP, using getline. *BUFFER must be NULL, or a heap-allocated pointer of *LENGTH bytes. Return the number of diff --git a/sysdeps/pthread/tst-cancel6.c b/sysdeps/pthread/tst-cancel6.c index 63e6d49707..49b7399353 100644 --- a/sysdeps/pthread/tst-cancel6.c +++ b/sysdeps/pthread/tst-cancel6.c @@ -20,12 +20,13 @@ #include #include +#include static void * tf (void *arg) { char buf[100]; - fgets (buf, sizeof (buf), arg); + xfgets (buf, sizeof (buf), arg); /* This call should never return. */ return NULL; } From patchwork Fri Apr 28 12:21:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 68480 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 5DE29387090C for ; Fri, 28 Apr 2023 12:38:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DE29387090C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685497; bh=nCZxT1bIS1P4gooR/RKEUAg07lfWnljLj5F12kzCr6U=; 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=FLVF4VmlNH/FvocdmEWb3xLN33WSB/oKzQ3Aoaxv6OAfmq3zyKBqm2AC4BUVQ1A/y LEJd3R0pdqSptdwtBtuH3Huu/FQLKNB6JoHZ+QAYXR+cyU73V8jxJJ7zXk4JzQz58J UFF0lo1xdw3RvCCAgGJg0IayDDE5clWHoFJ5Op+s= 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 598DC3857708 for ; Fri, 28 Apr 2023 12:35:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 598DC3857708 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-160-oyG67FEkMA6POwB9-M8QOQ-1; Fri, 28 Apr 2023 08:35:34 -0400 X-MC-Unique: oyG67FEkMA6POwB9-M8QOQ-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 DE9B8A0F380; Fri, 28 Apr 2023 12:35:33 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FE3FC15BA0; Fri, 28 Apr 2023 12:35:33 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 14/15] tests: Replace various function calls with their x variant Date: Fri, 28 Apr 2023 14:21:41 +0200 Message-Id: <20230428122142.928135-15-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-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" With fortification enabled, few function calls return result need to be checked, has they get the __wur macro enabled. --- misc/tst-error1.c | 2 +- nss/tst-reload2.c | 6 +++++- posix/tst-chmod.c | 9 +++++++-- posix/wordexp-test.c | 6 +++++- stdlib/test-canon.c | 7 ++++++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/misc/tst-error1.c b/misc/tst-error1.c index 9c4a62fbd0..65e3fd0c0e 100644 --- a/misc/tst-error1.c +++ b/misc/tst-error1.c @@ -9,7 +9,7 @@ static int do_test (int argc, char *argv[]) { mtrace (); - (void) freopen (argc == 1 ? "/dev/stdout" : argv[1], "a", stderr); + if (freopen (argc == 1 ? "/dev/stdout" : argv[1], "a", stderr)) {} /* Orient the stream. */ fwprintf (stderr, L"hello world\n"); char buf[20000]; diff --git a/nss/tst-reload2.c b/nss/tst-reload2.c index ba9b5b7687..b25e5e3528 100644 --- a/nss/tst-reload2.c +++ b/nss/tst-reload2.c @@ -121,7 +121,11 @@ do_test (void) /* Change the root dir. */ TEST_VERIFY (chroot ("/subdir") == 0); - chdir ("/"); + if (chdir ("/") < 0) + { + printf("Failed to change directory: %m"); + return 1; + } /* Check we're NOT using the "inner" nsswitch.conf. */ diff --git a/posix/tst-chmod.c b/posix/tst-chmod.c index b98a05a265..bec2d2b8eb 100644 --- a/posix/tst-chmod.c +++ b/posix/tst-chmod.c @@ -229,7 +229,12 @@ do_test (int argc, char *argv[]) close (fd); snprintf (buf, buflen, "%s/..", testdir); - chdir (buf); + if (chdir (buf)) + { + printf ("cannot change directory: %m\n"); + result = 1; + goto fail; + } /* We are now in the directory above the one we create the test directory in. */ @@ -349,7 +354,7 @@ do_test (int argc, char *argv[]) } fail: - chdir (startdir); + if (chdir (startdir)) {} /* Remove all the files. */ chmod (testdir, 0700); diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c index bae27d6cee..87d537c931 100644 --- a/posix/wordexp-test.c +++ b/posix/wordexp-test.c @@ -332,7 +332,11 @@ do_test (int argc, char *argv[]) if (cwd == NULL) cwd = ".."; - chdir (cwd); + if (chdir (cwd) < 0) + { + printf ("failed to change dir: %m"); + return 1; + } rmdir (tmpdir); return 0; diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c index 4edee73dd8..5a2e7e1e6e 100644 --- a/stdlib/test-canon.c +++ b/stdlib/test-canon.c @@ -154,7 +154,12 @@ do_test (int argc, char ** argv) } for (i = 0; i < (int) (sizeof (symlinks) / sizeof (symlinks[0])); ++i) - symlink (symlinks[i].value, symlinks[i].name); + if (symlink (symlinks[i].value, symlinks[i].name)) + { + printf ("%s: Unable to create symlink for %s -> %s\n", + argv[0], symlinks[i].name, symlinks[i].value); + ++errors; + } int has_dir = mkdir ("doesExist", 0777) == 0; From patchwork Fri Apr 28 12:21: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: 68477 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 523013850855 for ; Fri, 28 Apr 2023 12:37:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 523013850855 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682685459; bh=1Uy6PPGD33HksQe0koJild61jl/NvcWDuDAxAmWQ/uA=; 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=DpynHU2GYbgYe6FYO9olw1Qq15NuxeNxEOjS1E/RtluPJ3FT8cICE/CTmP1X4PiC+ JreA5Q4iuVmiLffdURaShpUGYRMxfpv3NeI4PEjonY0XoDotTuX7V68DGwL3sXj6QN oxZC+GoUeqD/LDk/lLBJJdQhqW6Vx3Al9g5y7/J0= 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 1F8503857716 for ; Fri, 28 Apr 2023 12:35:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F8503857716 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-475-8UEp9113M9CUeKtMCGrrbg-1; Fri, 28 Apr 2023 08:35:35 -0400 X-MC-Unique: 8UEp9113M9CUeKtMCGrrbg-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 C28433822DEA; Fri, 28 Apr 2023 12:35:34 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 26CE9C15BA0; Fri, 28 Apr 2023 12:35:34 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v4 15/15] tests: fix warn unused results Date: Fri, 28 Apr 2023 14:21:42 +0200 Message-Id: <20230428122142.928135-16-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-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.6 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" With fortification enabled, few function calls return result need to be checked, has they get the __wur macro enabled. --- 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 | 18 +++++++++++++++--- support/test-container.c | 4 ++-- sysdeps/pthread/tst-cancel16.c | 6 +++++- sysdeps/pthread/tst-cancel4.c | 6 ++++-- 11 files changed, 62 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..61fe893609 100644 --- a/stdlib/test-canon.c +++ b/stdlib/test-canon.c @@ -123,8 +123,15 @@ 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 +217,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);