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: Paul Eggert
Subject: [bug-gnulib] Re: bugs in regexp.c
Date: Fri, 11 Mar 2005 14:10:29 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

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".

>> I don't know how to reproduce it easily.
>
> main () {regcomp(NULL,"$*",0);}

As I understand it that's not portable code, since POSIX doesn't allow
the first arg of regcomp to be null.

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)
           abort ();
  if (regexec (&r, "ab$", 0, 0, 0) != 0)
          abort ();
  return 0;
}




reply via email to

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