www.digitalmars.com         C & C++   DMDScript  

c++ - regexp, Assertion failure


I've tried to use the RegExp class to parse a 8051 map file for certain 
lines. In case sensitive mode it works as expected, but terminates with 
an assertion when the attribute string is "i" for case insensitive.
This is a small program to reproduce the error:

//========= a.cpp ============
#include <stdio.h>
#include <regexp.h>

#define GEN_ERROR  1
#if GEN_ERROR == 0
#define  ATTRIB   NULL
#define  ATTRIB   "i"   // ignore case causes problem

char test_str1[] = "  D:00CCH         SYMBOL        TL2   ";
char pattern[]   = "([DX]:[0-9A-F]+H)[\t ]+([A-Z]+)[\t ]+([\\S]+)";

int main()
{  RegExp  rexp;
   if(rexp.compile(pattern, ATTRIB, 0) == 0)
      printf("Compile failed\n");
   else {
      printf("regexp compiled ok\n");
      if(rexp.test(test_str1) == 0)
         printf("Failed finding a match\n");
      else {
         printf("matched %d\n", rexp.re_nsub);
         for(int i=1; i<=3; ++i) {
            printf("%d => %.*s\n", i,
      }//if else
   }//if else
//=========== end a.cpp =============
Compile as console application with
  dmc a.cpp

Output in case insensitive mode:
   regexp compiled ok
   matched 3
   1 => D:00CCH
   2 => SYMBOL
   3 => TL2

Output in case sensitive mode:
   regexp compiled ok
   Assertion failure: '0' on line 921 in file '..\core\regexp.cpp'

   abnormal program termination

I don't have the file regexp.cpp so I can not look for the problem 

- Heinz
Oct 25 2012