[Gllug] [Somewhat OT] POSIX regex in C

Adrian McMenamin adrian at mcmen.demon.co.uk
Wed Jul 13 11:49:00 UTC 2011


On Wed, July 13, 2011 12:01 pm, Nix wrote:
> On 9 Jul 2011, Adrian McMenamin stated:
>
> You want a #define up here (_XOPEN_SOURCE, _GNU_SOURCE or something) to
> specify what language standard you're conforming to. The default is
> 'just ISO C', which is unlikely to be what you want.
>
>> #include <regex.h>
>>
>> struct blocklist* getnextblock(void** lastblock, void** head, char* buf)
>> {
>> 	printf("LINE:%s", buf);
>> 	regex_t reg;
>> 	regmatch_t addresses[3];
>> 	char pattern[1024] = "^([0-9a-f]+)-([0-9a-f]+)";
>> 	int xreg = regcomp(&reg, pattern, REG_EXTENDED|REG_NOSUB);
>> 	printf("Regcomp returns %d\n", xreg);
>> 	int match = regexec(&reg, buf, (size_t)3, addresses, 0);
>
> POSIX states:
>
>> If _nmatch_ is 0 or REG_NOSUB was set in the cflags argument to reg‐
>> comp(), then regexec() shall ignore the _pmatch_ argument.
>
> (nmatch == arg 3, pmatch == arg 4).
>
> So two of your arguments are useless


You are right of course - though I had just stuck that REG_NOSUB in when I
was trying to debug it/eliminate that as the issue.



>
> reg*() are in POSIX (and have been for fifteen years or more), and are
> very widely used, so you can trust that they work. Something else is
> wrong, but your example does not give us enough information to be sure
> what it is.
>

As it turned out the real issue was a leak elsewhere.


> --
> NULL && (void)
> --
> Gllug mailing list  -  Gllug at gllug.org.uk
> http://lists.gllug.org.uk/mailman/listinfo/gllug
>


--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list