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

Bug#586971: libc6-dev: REG_NOSUB prevents storing location of entire regex match



Package: libc6-dev
Version: 2.11.1-3
Severity: minor
Tags: upstream

/usr/include/regex.h says:

/* If this bit is set, then report only success or fail in regexec.
   If not set, then returns differ between not matching and errors.  */
#define REG_NOSUB (REG_NEWLINE << 1)

It doesn't say anything about not storing the location of the match
of the entire regex in __pmatch[0]. However, when REG_NOSUB is set,
the location is not stored as the test program below shows.

This may be the expected behaviour. In this case, it should be made
clear in the comment above, since the name of the constant suggests
it only affects sub-matches.

#include <stdio.h>
#include <regex.h>

int main ()
{
  regex_t r;
  regmatch_t m[1];
  int i;
  for (i = 0; i < 2; i++)
    {
      m[0].rm_so = m[0].rm_eo = -1;
      printf ("%s REG_NOSUB: ", i ? "with" : "without");
      if (regcomp (&r, "b", i * REG_NOSUB))
        printf ("error in regcomp\n");
      else if (regexec (&r, "abc", 1, m, 0))
        printf ("no match\n");
      else
        printf ("%i %i\n", m[0].rm_so, m[0].rm_eo);
    }
}

Output:

without REG_NOSUB: 1 2
with REG_NOSUB: -1 -1

-- System Information:
Debian Release: squeeze/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)

Versions of packages libc6-dev depends on:
ii  libc-dev-bin                  2.11.1-3   Embedded GNU C Library: Developmen
ii  libc6                         2.11.1-3   Embedded GNU C Library: Shared lib
ii  linux-libc-dev                2.6.32-15  Linux support headers for userspac



Reply to: