[PATCH] Fix non-mbs regex handling
Jakub Jelinek
jakub@redhat.com
Tue Feb 6 15:27:00 GMT 2001
Hi!
Although this patch is not strictly needed after MBS_SUPPORT switch, if
people take code from glibc they might be happy if bugs in it are fixed.
In this case for 32 byte bitmap (unsigned char)(32*8) is 0 so the comparison
is wrong.
2001-02-07 Jakub Jelinek <jakub@redhat.com>
* posix/regex.c (re_match_2_internal): Handle correctly 32 byte
bitmaps.
* posix/tst-regex.c: New test.
--- libc/posix/regex.c.jj Wed Feb 7 01:13:08 2001
+++ libc/posix/regex.c Wed Feb 7 01:13:40 2001
@@ -6776,7 +6776,7 @@ re_match_2_internal (bufp, string1, size
{
int not = (re_opcode_t) p1[3] == charset_not;
- if (c < (unsigned char) (p1[4] * BYTEWIDTH)
+ if (c < (unsigned) (p1[4] * BYTEWIDTH)
&& p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
not = !not;
--- libc/posix/tst-regex.c.jj Wed Feb 7 01:12:55 2001
+++ libc/posix/tst-regex.c Wed Feb 7 01:10:50 2001
@@ -0,0 +1,23 @@
+#include <sys/types.h>
+#include <regex.h>
+#include <stdio.h>
+
+int
+main (int argc, char *argv[])
+{
+ regex_t re;
+ regmatch_t mat[1];
+ int res = 1;
+
+ if (regcomp (&re, "[ax\xfe]*x", 0) != REG_NOERROR)
+ puts ("cannot compile expression \"[an\\xfe]*n\"");
+ else if (regexec (&re, "paxaxap", 1, mat, 0) == REG_NOMATCH)
+ puts ("no match");
+ else
+ {
+ printf ("match from %d to %d\n", mat[0].rm_so, mat[0].rm_eo);
+ res = mat[0].rm_so != 1 || mat[0].rm_eo != 5;
+ }
+
+ return res;
+}
Jakub
More information about the Libc-hacker
mailing list