c++ - Crash using aho-corasick algorothm? -


i got code aho-corasick algorithm here: http://www.komodia.com/aho-corasick .

i used guide said, added lines , built tree.

i did change using std wstring std string should not matter. changed typedef.

when use , search something, if not results found there no problem. when results found, std out of range exception.

it crashes here:

        if (aiterator==pnode->amap.end())             //no, check if have failure node             if (!pnode->pfailurenode)             {                 //no failure node, start @ root again                 pnode=&m_aroot;                  //reset search string                 smatchedstring="";                  //did switch?                 if (bswitch)                     //we need on                     --icount;                  //exit loop                 break;             }             else             {                 //what depth difference?                 unsigned short usdepth;                 usdepth=pnode->usdepth-pnode->pfailurenode->usdepth-1;                  //this how many chars remove                 smatchedstring=smatchedstring.substr(usdepth,smatchedstring.length()-usdepth); //crashes here!!                  //go failure node                 pnode=pnode->pfailurenode;                  //set switch                 bswitch=true;             }         else         {             //add char             smatchedstring+=rstring[icount];              //save new node             pnode=aiterator->second;              //exit loop             break;         }     } 

it crashes here:

smatchedstring=smatchedstring.substr(usdepth,smatchedstring.length()-usdepth);  

here variables:

enter image description here

i'm using implement censorship in game.

what cause crash?

i have strings added twice, cause problems?

thanks

one problem smatchedstring "u", while usdepth 3. results in substring third character (in 1 character string) length of -2.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -