public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: libc-alpha <libc-alpha@sourceware.org>, DJ Delorie <dj@redhat.com>
Subject: [PATCH] support: Set errno before testing it.
Date: Wed, 29 Apr 2020 17:30:16 -0400	[thread overview]
Message-ID: <970ad4c1-2666-3a54-c591-e52b8014bd40@redhat.com> (raw)

DJ,

I looked over the whole tree, and I only found on occurance of
TEST_COMPARE (errno, 0); (and some variants) where we forgot to set
errno to zero.

Likewise in test-container.c we have an instance of strtol which doesn't
check error returns.

I've put these together in one patch to make testing easier. It fixes
both cases, the missing check, and the potentially broken check (depends
on what gets called before parse_int()).

OK for master?

8< --- 8< --- 8<
From 0adf117887d13925d9a00be1a0abd07ded6adfce Mon Sep 17 00:00:00 2001
From: Carlos O'Donell <carlos@redhat.com>
Date: Wed, 29 Apr 2020 16:31:29 -0400
Subject: [PATCH] support: Set errno before testing it.

In test-conainer we should set errno to 0 before calling chmod,
and check after with TEST_COMPARE.

In tst-support_capture_subprocess we should set errno to 0 before
checking it after the call to strtol.

Tested on x86_64.
---
 support/test-container.c                 | 2 ++
 support/tst-support_capture_subprocess.c | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/support/test-container.c b/support/test-container.c
index 08d5195b7e..afc23db148 100644
--- a/support/test-container.c
+++ b/support/test-container.c
@@ -940,7 +940,9 @@ main (int argc, char **argv)
 	    else if (nt == 3 && strcmp (the_words[0], "chmod") == 0)
 	      {
 		long int m;
+		errno = 0;
 		m = strtol (the_words[1], NULL, 0);
+		TEST_COMPARE (errno, 0);
 		if (chmod (the_words[2], m) < 0)
 		    FAIL_EXIT1 ("chmod %s: %s\n",
 				the_words[2], strerror (errno));
diff --git a/support/tst-support_capture_subprocess.c b/support/tst-support_capture_subprocess.c
index 67bbc1e8ae..6094dba49e 100644
--- a/support/tst-support_capture_subprocess.c
+++ b/support/tst-support_capture_subprocess.c
@@ -133,7 +133,9 @@ static int
 parse_int (const char *str)
 {
   char *endptr;
-  long int ret = strtol (str, &endptr, 10);
+  long int ret;
+  errno = 0;
+  ret = strtol (str, &endptr, 10);
   TEST_COMPARE (errno, 0);
   TEST_VERIFY (ret >= 0 && ret <= INT_MAX);
   return ret;
-- 
2.21.1


-- 
Cheers,
Carlos.


             reply	other threads:[~2020-04-29 21:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29 21:30 Carlos O'Donell [this message]
2020-04-29 22:54 ` DJ Delorie
2020-04-30 20:30   ` Carlos O'Donell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=970ad4c1-2666-3a54-c591-e52b8014bd40@redhat.com \
    --to=carlos@redhat.com \
    --cc=dj@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).