[Bug c/14747] New: regexec gives incorrect response

ron at vaniwaarden dot org gcc-bugzilla@gcc.gnu.org
Fri Mar 26 17:15:00 GMT 2004


[vaniwaar@vaniwaar-w2k ~]$ g++ --version
g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I could not find this in the database and it appears to be fixed in 3.3.2. 
However, it could have been fixed accidentially, partially or incidentally, so I
submitted the bug anyway.  The following code should output 'Success.' but it
outputs "Didn't find a match (for regexec)"

#include <iostream>
#include <sys/types.h>
#include <regex.h>

const char* haystack = 
"2\n3";

const char* needle =
".+\n3";


int main()
{
  using namespace std;
  regex_t r;
  int failed_p = regcomp(&r, needle,
			       REG_EXTENDED | REG_NOSUB);
  int result = regexec(&r, haystack, 0, NULL, 0);
  switch (result)
  {
  case REG_NOERROR:
    cout<<"Success."<<endl;break;
  case REG_NOMATCH:
    cout<<"Didn't find a match (for regexec)."<<endl;break;
  case REG_BADPAT:
    cout<<" Invalid pattern."<<endl;break;
  case REG_ECOLLATE:
    cout<<" Not implemented."<<endl;break;
  case REG_ECTYPE:
    cout<<" Invalid character class name."<<endl;break;
  case REG_EESCAPE:
    cout<<" Trailing backslash."<<endl;break;
  case REG_ESUBREG:
    cout<<" Invalid back reference."<<endl;break;
  case REG_EBRACK:
    cout<<" Unmatched left bracket."<<endl;break;
  case REG_EPAREN:
    cout<<" Parenthesis imbalance."<<endl;break;
  case REG_EBRACE:
    cout<<" Unmatched \\{."<<endl;break;
  case REG_BADBR:
    cout<<" Invalid contents of \\{\\}."<<endl;break;
  case REG_ERANGE:
    cout<<" Invalid range end."<<endl;break;
  case REG_ESPACE:
    cout<<" Ran out of memory."<<endl;break;
  case REG_BADRPT:
    cout<<" No preceding re for repetition op."<<endl;break;
  case REG_EEND:
    cout<<" Premature end."<<endl;break;
  case REG_ESIZE:
    cout<<" Compiled pattern bigger than 2^16 bytes."<<endl;break;
  case REG_ERPAREN:
    cout<<" Unmatched ) or \\); not returned from regcomp."<<endl;break;
  default:
    cout<<"unknown result:"<<result<<endl;
  }
}

-- 
           Summary: regexec gives incorrect response
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ron at vaniwaarden dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14747



More information about the Gcc-bugs mailing list