1

ここでaho-corasickアルゴリズムのコードを入手しました:http ://www.komodia.com/aho-corasick 。

ガイドが言ったようにそれを使用し、線を追加してツリーを構築しました。

ただし、stdwstringからstdstringに変更しましたが、それは問題ではありません。typedefを変更しました。

それを使って何かを探しても、結果が見つからなくても問題ありません。結果が見つかると、標準の範囲外の例外が発生します。

ここでクラッシュします:

        if (aIterator==pNode->aMap.end())
            //No, check if we have failure node
            if (!pNode->pFailureNode)
            {
                //No failure node, start at root again
                pNode=&m_aRoot;

                //Reset search string
                sMatchedString="";

                //Did we do a switch?
                if (bSwitch)
                    //We need to do this over
                    --iCount;

                //Exit this loop
                break;
            }
            else
            {
                //What is the depth difference?
                unsigned short usDepth;
                usDepth=pNode->usDepth-pNode->pFailureNode->usDepth-1;

                //This is how many chars to remove
                sMatchedString=sMatchedString.substr(usDepth,sMatchedString.length()-usDepth); //CRASHES HERE!!

                //Go to the failure node
                pNode=pNode->pFailureNode;

                //Set to switch
                bSwitch=true;
            }
        else
        {
            //Add the char
            sMatchedString+=rString[iCount];

            //Save the new node
            pNode=aIterator->second;

            //Exit the loop
            break;
        }
    }

ここでクラッシュします:

sMatchedString=sMatchedString.substr(usDepth,sMatchedString.length()-usDepth); 

変数は次のとおりです。

ここに画像の説明を入力してください

私はこれを使用して、ゲームに検閲を実装しています。

何が原因でクラッシュする可能性がありますか?

いくつかの文字列を2回追加しましたが、問題が発生する可能性がありますか?

ありがとう

4

1 に答える 1

1

考えられる問題の1つsMatchedString"u"、usDepthが3であるのに対し、です。これにより、長さが-2の3番目の文字(1文字の文字列)からの部分文字列が生成されます。

于 2012-06-05T06:33:19.417 に答える