This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: regex_t internals: can we use re_magic to tell whether a regex has been regcomp'd?

On Aug 10 19:07, Fischer, Matthew L wrote:
> We are porting code from Linux that is attempting to determine whether
> a regular expression has been properly regcomp'd and not freed.  The
> code from Linux is looking into the buffer inside regex_t.   On

Which is kind of scary, IMHO.

Using the internals of the regex_t structure other than the ones blessed
by the POSIX standard is a sure way to write non-portable code.  See
The only officially documented member of regex_t is re_nsub.

So, why does the code check the internals at all?  Why is it important
that something has been allocated or not?  Shouldn't the application
code be happy to rely solely on the return value of regcomp?

> Cygwin, the "buffer" (not the same field name) is hidden inside
> re_guts which has a comment that dissuades us from using it for this
> purpose.

Rightfully.  Please note that the regex code is *not* Cygwin-specific.
This code is actually FreeBSD code, with only minor changes to port it
to Cygwin, plus an extension to allow the GNU \< and \> expressions.

> However, from looking at the Cygwin implementation, it looks
> like if re_magic is != 0 then the regexp is valid and has been
> regcomp'd and not regfree'd.  Is this interpretation correct?

Well, I never actually examined the guts of regcomp/regfree more than
necessary, but it seems you're right.  No guarantees, though.  IMHO, if
the application code has to check the internals of the regex_t structure
to know if it called regfree on it, it's a bug in the application.
Rather than doing that, it should keep track of its regcomp/regfree
calls by using an external state variable.


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]