From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by sourceware.org (Postfix) with ESMTP id CAE9A3856DF8 for ; Mon, 3 Jul 2023 17:52:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CAE9A3856DF8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=nabijaczleweli.xyz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nabijaczleweli.xyz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1688406753; bh=eLPv6OEL+9scvYx7veIssARneZWe+AWlY3YvBLkA1aM=; h=Date:From:Cc:Subject:References:In-Reply-To:From; b=dJvgUOwp4bvnGdy/5YgP/TavVzN8eajHk5OBrWQfFEqLLiYwuiRzJfBHMQNz53UTo aBN2b1iXekWPRc5qBwH6uM4iQePEeksQqsZVZI0344mxx5IcZ50l7pOZVqXsowIGzU g7TnlTcRoReegIZTslhmuBY2EJIfB2Apyj11240SdNqb27e+D2F7fJDtebtVMbnf0k QSaNVG3Uc+UhxADhztDAxy39S2sxAZnVw+49ucDcuxNd9W5KaCC9zZ9cMI4fzZlfCM h5ctzN6qusHXSGLwEr61CNmuigytnhYp2PZSTOcrvzKPFwrJk0Dsfqpe5Im1uihsMV GYNes9cGho7mg== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 40FEC1C6E; Mon, 3 Jul 2023 19:52:33 +0200 (CEST) Date: Mon, 3 Jul 2023 19:52:32 +0200 From: =?utf-8?B?0L3QsNCx?= Cc: Carlos O'Donell , Adhemerval Zanella Netto , Paul Eggert , libc-alpha@sourceware.org Subject: [PATCH v9 3/3] posix: add test for REG_STARTEND Message-ID: <5faaa526b871a76cb1e272fe886bf744f6893b9d.1688406717.git.nabijaczleweli@nabijaczleweli.xyz> References: <56ba55edd43630bdd5658c8648c0ef3ef7d6f938.1688406716.git.nabijaczleweli@nabijaczleweli.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="flqefpikb5fkl5no" Content-Disposition: inline In-Reply-To: <56ba55edd43630bdd5658c8648c0ef3ef7d6f938.1688406716.git.nabijaczleweli@nabijaczleweli.xyz> User-Agent: NeoMutt/20230517 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_INFOUSMEBIZ,MISSING_HEADERS,PDS_RDNS_DYNAMIC_FP,RDNS_DYNAMIC,SPF_HELO_PASS,SPF_PASS,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 List-Id: --flqefpikb5fkl5no Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable This test passes on NetBSD, the illumos gate, musl with https://www.openwall.com/lists/musl/2023/05/14/1, and now glibc. It's nothing revolutionary and the behaviour it tests is largely guaranteed by the 4.4BSD-Lite manual; nevertheless, it used to fail with tst-reg-startend.c: ^a: a^@c: no match$ tst-reg-startend.c: ^a: a^@c: wanted {1, 2}, got {1, 4}$ tst-reg-startend.c: ^a: abc: no match$ tst-reg-startend.c: ^a: abc: wanted {1, 2}, got {1, 4}$ tst-reg-startend.c: ^a.c$: a^@c: no match$ tst-reg-startend.c: ^a.c$: abc: no match$ tst-reg-startend.c: ^a.*c$: a^@c: no match$ tst-reg-startend.c: ^a.*c$: abc: no match$ tst-reg-startend.c: ^a[^c]c$: a^@c: no match$ tst-reg-startend.c: ^a[^c]c$: abc: no match$ tst-reg-startend.c: ^a..: a^@c: no match$ tst-reg-startend.c: ^a..: abc: no match$ tst-reg-startend.c: ..c: a^@c: no match$ Signed-off-by: Ahelenia Ziemia=C5=84ska --- posix/Makefile | 1 + posix/tst-reg-startend.c | 142 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 posix/tst-reg-startend.c diff --git a/posix/Makefile b/posix/Makefile index ad43cbdec6..10b64206f1 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -296,6 +296,7 @@ tests :=3D \ tst-posix_spawn-setsid \ tst-preadwrite \ tst-preadwrite64 \ + tst-reg-startend \ tst-regcomp-truncated \ tst-regex \ tst-regex2 \ diff --git a/posix/tst-reg-startend.c b/posix/tst-reg-startend.c new file mode 100644 index 0000000000..854d430676 --- /dev/null +++ b/posix/tst-reg-startend.c @@ -0,0 +1,142 @@ +/* This is free and unencumbered software released into the public domain. + + Anyone is free to copy, modify, publish, use, compile, sell, or + distribute this software, either in source code form or as a compiled + binary, for any purpose, commercial or non-commercial, and by any + means. + + In jurisdictions that recognize copyright laws, the author or authors + of this software dedicate any and all copyright interest in the + software to the public domain. We make this dedication for the benefit + of the public at large and to the detriment of our heirs and + successors. We intend this dedication to be an overt act of + relinquishment in perpetuity of all present and future rights to this + software under copyright law. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. */ + + +#include +#include +#include +#include +#include +#include +#include + + +static const regmatch_t bound =3D {1, 4}; + + +struct reg_res { + const char *regex; + regmatch_t result; +}; +static const struct reg_res reg_res_ac[] =3D { + {"^a", {1, 2}}, + {"c$", {3, 4}}, + {"^a.c$", {1, 4}}, + {"^a.*c$", {1, 4}}, + {"^a[^c]c$", {1, 4}}, + {"^a..", {1, 4}}, + {"..c", {1, 4}}, + {"[^z]c", {2, 4}}, + {} +}; +static const char *const data_ac[] =3D {"_a\0cdef", "_abcdef", NULL}; + +static const struct reg_res reg_res_aa[] =3D { + {"^", {1, 1}}, + {"^a", {1, 2}}, + {"a$", {3, 4}}, + {"^\\(a\\).\\1$", {1, 4}}, + {"^a[^a]*" , {1, 3}}, + {} +}; +static const char *const data_aa[] =3D {"_a\0adef", "_abadef", NULL}; + + +static void +testbunch (const struct reg_res *reg_reses, const char *const *const data) +{ +#define BASEERR(data) \ + support_record_failure (), \ + fprintf (stdout, __FILE__ ": %s: ", reg_reses->regex), \ + fwrite (data + bound.rm_so, 1, bound.rm_eo - bound.rm_so, stdout) + + for (; reg_reses->regex; ++reg_reses) + { + regex_t rgx; + assert (!regcomp (&rgx, reg_reses->regex, 0)); + + for (const char *const *dt =3D data; *dt; ++dt) + { + regmatch_t match =3D bound; + if (regexec (&rgx, *dt, 1, &match, REG_STARTEND)) + BASEERR(dt), fputs (": no match\n", stdout); + + if (memcmp(&match, ®_reses->result, sizeof (regmatch_t))) + BASEERR(dt), fprintf (stdout, ": wanted {%d, %d}, got {%d, %d}= \n", + (int)reg_reses->result.rm_so, + (int)reg_reses->result.rm_eo, + (int)match.rm_so, (int)match.rm_eo); + } + + regfree(&rgx); + } +} + + +struct mb_data_exp { + const char *data; + bool exp; +}; +static const struct mb_data_exp mb_data_exp[] =3D { + {"_aa=C4=87def", false}, + {"_a=C4=87def", true}, + {} +}; + +static void +testmb (void) +{ + regex_t rgx; + const struct reg_res reg_reses[] =3D {{"a=C4=87"}}; + assert (!regcomp (&rgx, reg_reses->regex, 0)); + + for (const struct mb_data_exp *de =3D mb_data_exp; de->data; ++de) + { + regmatch_t match =3D bound; + if (regexec (&rgx, de->data, 1, &match, REG_STARTEND) =3D=3D de->exp) + BASEERR(de->data), fprintf (stdout, ": %s match\n", + de->exp ? "no" : "yes"); + + if (memcmp(&match, &bound, sizeof (regmatch_t))) + BASEERR(de->data), fprintf (stdout, ": wanted {%d, %d}, got {%d, %= d}\n", + (int)bound.rm_so, (int)bound.rm_eo, + (int)match.rm_so, (int)match.rm_eo); + } + + regfree(&rgx); +} + + +static int +do_test (void) +{ + assert (setlocale (LC_ALL, "C.UTF-8")); + + testbunch (reg_res_ac, data_ac); + testbunch (reg_res_aa, data_aa); + testmb (); + return 0; +} + + +#include --=20 2.39.2 --flqefpikb5fkl5no Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEfWlHToQCjFzAxEFjvP0LAY0mWPEFAmSjCt8ACgkQvP0LAY0m WPHCbg/+PZbdBumvqigiRYnOs5qlZB9pWndqJncK/L/hUvOuIRW8gSLIEp+UrLp1 hiLXWTMf0oL0OpByfbXRg9xzI50t6mys4ShZWs0nIwD4d1nbjTsjMN7nACVvTVjZ iYtNN8ENGNaUAR+Hp+n+rFQ1rp1RQV1NWIaiSKsrduPIX+7ScIkfkXI8T84uxrXi u8PEB9H/dn+9FPhOwC021GY0P8Fhth7u0iza2KCQUIyaokr1o4IFtWwSn0/roV5Q fWWhRVxLaqiMbBFJ6gCayBqdXiNpXUI2QHSm7XHFuprUX1Gi2lNby8zuQ5W+mCFz qtZVPNXW9G63f2VF51A76Vpn1X1kjvuj3XFWhEXJWWqdrYH3E0CxWNunECwAng1K nSjMyMuKrwyX+xKQeTjM6KtkVrWlSTz13cJyGRHil+oxwZ4qVnKoDC9q2pwXF5dt C+EU8XKoZ4O46uR6gug1et/cfhR2DhNsmfdTGA5OiA+abmfaYIblGNVrESl7zbmJ EkjvqbRjjIyjmwx33SKvRAn5uIaX2ofwHAapczRe/PJbJbEGy6r4wTFHBHIWYnqv P5J4BsCHk2zqKDqd5rhvwg/IJL482r9QR7iisxOppJevrL0lMm1XLTo19JZL3Aeq MAR8dP48vEnCDtMq7v2iDTR1EhDKYUpaNyyUiM9DZSeWoOZL9tw= =1FY6 -----END PGP SIGNATURE----- --flqefpikb5fkl5no--