git-strtol-test
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Thu, 17 Mar 2022 21:37:00 +0000 (21:37 +0000)
committerAurelien Jarno <aurel32@debian.org>
Thu, 17 Mar 2022 21:37:00 +0000 (21:37 +0000)
Committed for glibc 2.32

commit 183083c35972611e7786c7ee0c96d7da571631ed
Author: Carlos O'Donell <carlos@redhat.com>
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 <dj@redhat.com>
Gbp-Pq: Topic hurd-i386
Gbp-Pq: Name git-strtol-test.diff

support/test-container.c
support/tst-support_capture_subprocess.c

index 4c58254558dc172c513cec9ba563216fa854674d..843227dd81209d95e30e7709a221101e8c8f6a04 100644 (file)
@@ -902,7 +902,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));
index 67bbc1e8ae4d935c9f4177d9e12d5d6f8cb7d851..6094dba49e81ec6ece82a06667c86b824ca10fdb 100644 (file)
@@ -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;