OpenSiv3D
OpenSiv3D copied to clipboard
Onigurumaの`ONIG_REGION_NOTPOS`の考慮漏れ
エラーの内容 | Describe the runtime error
RegExp::match()
を使用する際、パターンに対してキャプチャに失敗するような入力を行うとstd::out_of_range例外が発生します。
Onigurumaではキャプチャに失敗するとRegionのbeg
,end
にONIG_REGION_NOTPOS
(-1)が代入されるようになっており、Siv3D側でそれを考慮しないまま処理をするため例外になったようです。
https://github.com/Siv3D/OpenSiv3D/blob/cb0b930bdc46700a87abd166ff3d921a51800aed/Siv3D/src/Siv3D/RegExp/RegExpDetail.cpp#L117-L123
また、破壊的変更になりますが、例えばMatchResults
から帰る値をStringView
からOptional<StringView>
にするのが良さそうに思います。
再現方法 | To Reproduce
# include <Siv3D.hpp> // OpenSiv3D v0.6.5
void Main()
{
// abc
// def
for (auto result : UR"(([^ ]+)( .+)?)"_re.match(U"abc def"))
{
Console << result;
}
// [std::out_of_range] StringView::substr(): index out of range
for (auto result : UR"(([^ ]+)( .+)?)"_re.match(U"abc"))
{
Console << result;
}
}
発生環境(デスクトップの場合) | Desktop (please complete the following information):
- OS: Windows 11
- バージョン | Version: OpenSiv3D v0.6.5
- GPU: GeForce RTX 3070
備考 | Additional context