From: Nigel Kukard <nkukard@LBSD.net>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: [musl] Different results with regex.h between Musl and Libc
Date: Mon, 10 Jun 2024 05:38:36 +0000 [thread overview]
Message-ID: <4b595a5b-2164-4bf2-af8b-80992eb0a0fe@LBSD.net> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 2036 bytes --]
Hi there,
I'm wondering if someone could possibly point out what I'm doing wrong here.
I tried searching the mailing list for similar topics, I found some
relating to POSIX regex but none that really dealt with this issue with
extended regex. I also didn't find anything really addressing this on
https://wiki.musl-libc.org/functional-differences-from-glibc.html.
If I missed something I'm terribly sorry.
Musl output (Alpine 3.20), musl-1.2.5-r1...
The input '37' matches the pattern '^([0-9]*)?\.?([0-9]*)?$'
Match 0: 37
Match 1:
Match 2: 37
Glibc output (ArchLinux), glibc 2.39+r52+gf8e4623421-1...
The input '37' matches the pattern '^([0-9]*)?\.?([0-9]*)?$'
Match 0: 37
Match 1: 37
Match 2:
Test code...
/*--------------------*/
#include <stdio.h>
#include <regex.h>
int main() {
const char *pattern = "^([0-9]*)?\\.?([0-9]*)?$";
const char *input = "37";
regex_t regex;
regmatch_t matches[3];
int ret;
ret = regcomp(®ex, pattern, REG_EXTENDED);
if (ret) {
fprintf(stderr, "Could not compile regex\n");
return 1;
}
ret = regexec(®ex, input, 3, matches, 0);
if (!ret) {
printf("The input '%s' matches the pattern '%s'\n", input,
pattern);
for (int i = 0; i < 3; i++) {
if (matches[i].rm_so != -1) {
printf("Match %d: %.*s\n", i, matches[i].rm_eo -
matches[i].rm_so, input + matches[i].rm_so);
}
}
} else if (ret == REG_NOMATCH) {
printf("The input '%s' does not match the pattern '%s'\n",
input, pattern);
} else {
char msgbuf[100];
regerror(ret, ®ex, msgbuf, sizeof(msgbuf));
fprintf(stderr, "Regex match failed: %s\n", msgbuf);
return 1;
}
regfree(®ex);
return 0;
}
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
next reply other threads:[~2024-06-10 5:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-10 5:38 Nigel Kukard [this message]
2024-06-10 11:47 ` [musl] " Valery Ushakov
2024-06-10 15:56 ` Rich Felker
2024-06-10 17:57 ` Valery Ushakov
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=4b595a5b-2164-4bf2-af8b-80992eb0a0fe@LBSD.net \
--to=nkukard@lbsd.net \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).