From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2191) id A287D389852B; Thu, 30 Apr 2020 20:28:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A287D389852B Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Carlos O'Donell To: glibc-cvs@sourceware.org Subject: [glibc] support: Set errno before testing it. X-Act-Checkin: glibc X-Git-Author: Carlos O'Donell X-Git-Refname: refs/heads/master X-Git-Oldrev: df6c63ebbce9679e755f0ecc716a33babee5d008 X-Git-Newrev: 183083c35972611e7786c7ee0c96d7da571631ed Message-Id: <20200430202828.A287D389852B@sourceware.org> Date: Thu, 30 Apr 2020 20:28:28 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Apr 2020 20:28:28 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=183083c35972611e7786c7ee0c96d7da571631ed commit 183083c35972611e7786c7ee0c96d7da571631ed Author: Carlos O'Donell Date: Wed Apr 29 16:31:29 2020 -0400 support: Set errno before testing it. In test-conainer we should set errno to 0 before calling strtol, 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. Reviewed-by: DJ Delorie Diff: --- 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;