From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12544 Path: news.gmane.org!.POSTED!not-for-mail From: Bruno Haible Newsgroups: gmane.comp.lib.gnulib.bugs,gmane.linux.lib.musl.general Subject: test-getopt-posix fails on musl Date: Sat, 24 Feb 2018 10:31:55 +0100 Message-ID: <1714550.SfedhZ9LKS@omega> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart24510937.1anYjGFEyF" Content-Transfer-Encoding: 7Bit X-Trace: blaine.gmane.org 1519464614 25124 195.159.176.226 (24 Feb 2018 09:30:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 24 Feb 2018 09:30:14 +0000 (UTC) User-Agent: KMail/5.1.3 (Linux/4.4.0-112-generic; KDE/5.18.0; x86_64; ; ) Cc: bug-gnulib@gnu.org To: musl@lists.openwall.com Original-X-From: bug-gnulib-bounces+gnu-bug-gnulib=m.gmane.org@gnu.org Sat Feb 24 10:30:09 2018 Return-path: Envelope-to: gnu-bug-gnulib@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1epW9h-000680-8M for gnu-bug-gnulib@m.gmane.org; Sat, 24 Feb 2018 10:30:09 +0100 Original-Received: from localhost ([::1]:49142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epWBj-0000pa-OQ for gnu-bug-gnulib@m.gmane.org; Sat, 24 Feb 2018 04:32:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1epWBX-0000pK-2w for bug-gnulib@gnu.org; Sat, 24 Feb 2018 04:32:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1epWBT-0002oj-Sv for bug-gnulib@gnu.org; Sat, 24 Feb 2018 04:32:03 -0500 Original-Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::3]:23223) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1epWBT-0002lI-5U for bug-gnulib@gnu.org; Sat, 24 Feb 2018 04:31:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1519464717; s=strato-dkim-0002; d=clisp.org; h=Content-Transfer-Encoding:Content-Type:Message-ID:Date:Subject:Cc: To:From:X-RZG-CLASS-ID:X-RZG-AUTH; bh=lGwbyRwDn6uaWvQ8TPIwrPJzUvh0uiLncPsNh/qjBvc=; b=cg6mIIpdaO+UKXOyAYyzsH6/xOEm5iQEaZGBMAnlw4ZNm02Cxug+uTWFc3u3TVmSok WUIategsKWAmlFNF093+97VQWRz/j0k2QAyu0MP1KD/E/K2ONDgfreIIaUDqawTd0qNA tPwM7ecxxofnuJA8HjRmd/2QJG51PWYbuPiH7aMr6YriuGxJftHIplNod/fQqpMZeYmg 9yTfLKOn4bhaj/ZmPjrzHbIXkPk8Ic+zEQk+aEEGRF9eQFQx5orCo1nt3SrMxyp8GD2S LQUAhsiE+CobRGGnh6F22NdI64T8kLx4ZvxY6SNEOWtEW7BmDEHwgDk5ogv5ghG1jd8y INvg== X-RZG-AUTH: :Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGafwy/s= X-RZG-CLASS-ID: mo00 Original-Received: from bruno.haible.de (dslb-088-068-035-056.088.068.pools.vodafone-ip.de [88.68.35.56]) by smtp.strato.de (RZmta 42.18 DYNA|AUTH) with ESMTPSA id z09455u1O9Vu7KI (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Sat, 24 Feb 2018 10:31:56 +0100 (CET) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5300::3 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+gnu-bug-gnulib=m.gmane.org@gnu.org Original-Sender: "bug-gnulib" Xref: news.gmane.org gmane.comp.lib.gnulib.bugs:38465 gmane.linux.lib.musl.general:12544 Archived-At: This is a multi-part message in MIME format. --nextPart24510937.1anYjGFEyF Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Hi, On Alpine Linux 3.7.0, which uses musl libc, the gnulib test 'test-getopt-posix' fails. To me, this looks like a POSIX compliance bug of musl. Find attached a reduced test case. $ gcc foo.c -Wall $ ./a.ou t foo.c:134: assertion 'options[0] == ':' || ((options[0] == '-' || options[0] == '+') && options[1] == ':')' failed Reference: POSIX http://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html --nextPart24510937.1anYjGFEyF Content-Disposition: attachment; filename="foo.c" Content-Transfer-Encoding: 7Bit Content-Type: text/x-csrc; charset="UTF-8"; name="foo.c" /* POSIX and glibc provide the getopt() function in , see http://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html https://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html But gnulib provides the getopt() function in , not in . Nevertheless the getopt() function should also be found in . */ #include #include #include #include #include #define TEST_GETOPT_TMP_NAME "test-getopt-posix.tmp" /* This test intentionally remaps stderr. So, we arrange to have fd 10 (outside the range of interesting fd's during the test) set up to duplicate the original stderr. */ #define BACKUP_STDERR_FILENO 10 #define ASSERT_STREAM myerr #ifndef FALLTHROUGH # if __GNUC__ < 7 # define FALLTHROUGH ((void) 0) # else # define FALLTHROUGH __attribute__ ((__fallthrough__)) # endif #endif /* Define ASSERT_STREAM before including this file if ASSERT must target a stream other than stderr. */ #ifndef ASSERT_STREAM # define ASSERT_STREAM stderr #endif /* ASSERT (condition); verifies that the specified condition is fulfilled. If not, a message is printed to ASSERT_STREAM if defined (defaulting to stderr if undefined) and the program is terminated with an error code. This macro has the following properties: - The programmer specifies the expected condition, not the failure condition. This simplifies thinking. - The condition is tested always, regardless of compilation flags. (Unlike the macro from .) - On Unix platforms, the tester can debug the test program with a debugger (provided core dumps are enabled: "ulimit -c unlimited"). - For the sake of platforms where no debugger is available (such as some mingw systems), an error message is printed on the error stream that includes the source location of the ASSERT invocation. */ #define ASSERT(expr) \ do \ { \ if (!(expr)) \ { \ fprintf (ASSERT_STREAM, "%s:%d: assertion '%s' failed\n", \ __FILE__, __LINE__, #expr); \ fflush (ASSERT_STREAM); \ abort (); \ } \ } \ while (0) static FILE *myerr; int main (void) { /* This test validates that stderr is used correctly, so move the original into fd 10. */ if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL) return 2; ASSERT (freopen (TEST_GETOPT_TMP_NAME, "w", stderr) == stderr); /* These default values are required by POSIX. */ ASSERT (optind == 1); ASSERT (opterr != 0); setenv ("POSIXLY_CORRECT", "1", 1); int start = 1; { int a_seen = 0; int b_seen = 0; const char *p_value = NULL; const char *q_value = NULL; int non_options_count = 0; int unrecognized = 0; bool output; int argc = 0; const char *argv[10]; argv[argc++] = "program"; argv[argc++] = "-p"; argv[argc++] = "foo"; argv[argc++] = "-:"; argv[argc++] = "-a"; argv[argc++] = "bar"; argv[argc] = NULL; optind = start; opterr = 42; { const char *options = "abp:q:"; int c; int pos = ftell (stderr); while ((c = getopt (argc, (char **) argv, options)) != -1) { switch (c) { case 'a': a_seen++; break; case 'b': b_seen++; break; case 'p': p_value = optarg; break; case 'q': q_value = optarg; break; case '\1': /* Must only happen with option '-' at the beginning. */ ASSERT (options[0] == '-'); non_options_count++; break; case ':': /* Must only happen with option ':' at the beginning. */ ASSERT (options[0] == ':' || ((options[0] == '-' || options[0] == '+') && options[1] == ':')); FALLTHROUGH; case '?': unrecognized = optopt; break; default: unrecognized = c; break; } } output = pos < ftell (stderr); } ASSERT (a_seen == 1); ASSERT (b_seen == 0); ASSERT (p_value != NULL && strcmp (p_value, "foo") == 0); ASSERT (q_value == NULL); ASSERT (non_options_count == 0); ASSERT (unrecognized == ':'); ASSERT (optind == 5); ASSERT (output); } ASSERT (fclose (stderr) == 0); ASSERT (remove (TEST_GETOPT_TMP_NAME) == 0); return 0; } --nextPart24510937.1anYjGFEyF--