bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gnulib] Re: bugs in regexp.c


From: Sam Steingold
Subject: [bug-gnulib] Re: bugs in regexp.c
Date: Fri, 18 Mar 2005 11:03:07 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt)

> * Paul Eggert <address@hidden> [2005-03-11 14:10:29 -0800]:
>
> Sam Steingold <address@hidden> writes:
>
>>> * Paul Eggert <address@hidden> [2005-03-10 16:29:50 -0800]:
>>>
>>> Sam Steingold <address@hidden> writes:
>>>
>>>>>> 3. regcomp("$*"): "Invalid preceding regular expression"
>>>>>> 8. regcomp("[[:xdigit]+") works, but when the result is matched against
>>>>>>    "0[x:dig", it matches just "[", not "[x:dig"
>>>
>>> (8) violates a "shall" so it's not a good test case.
>>
>> then why doesn't regcomp signal an error?
>
> Because regcomp is required to signal an error only for invalid
> regular expressions that do not have undefined behavior.  As I
> understand it (8) has undefined behavior, so as far as POSIX is
> concerned regcomp can do anything it pleases (including dump core).
> For more, please see
> <http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html>
> and look for "invalid".

indeed, regcomp is not _required_ to signal an error in this case,
but I think it is a good practice to treat undefined behavior as an
error.  this encourages safe portable code.

>>> I don't know how to reproduce it easily.
>
> I tried to correct it as follows, using the gnulib version of regex.h
> and regex.c, but this test case worked for me.  Do you have a complete
> example illustrating the problem?
>
> #include <sys/types.h>
> #include <regex.h>
>
> int
> main (int argc, char **argv)
> {
>   regex_t r;
>   if (regcomp (&r, "$*", 0) != 0)

       (regcomp (&r, "$*", REG_EXTENDED) != 0)

>          abort ();
>   if (regexec (&r, "ab$", 0, 0, 0) != 0)
>         abort ();
>   return 0;
> }

abnormal program termination

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.openvotingconsortium.org/> <http://www.memri.org/>
<http://www.jihadwatch.org/> <http://www.dhimmi.com/>
Warning! Dates in calendar are closer than they appear!





reply via email to

[Prev in Thread] Current Thread [Next in Thread]