Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_mm access of memory outside of allocated space is fixed #31

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mimetic/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ template<typename Iterator>
Iterator find_bm(Iterator bit, Iterator eit, const std::string& word, const std::random_access_iterator_tag&)
{
int bLen = word.length();
int sourceLen = std::distance(bit, eit);
const char* pWord = word.c_str();
int i, t, shift[256];
unsigned char c;
Expand All @@ -56,17 +57,17 @@ Iterator find_bm(Iterator bit, Iterator eit, const std::string& word, const std:
shift[i] = bLen;

for(i = 0; i < bLen; ++i)
shift[ (unsigned char) pWord[i] ] = bLen -i - 1;
shift[ static_cast<unsigned char>( pWord[i] ) ] = bLen -i - 1;

for(i = t = bLen-1; t >= 0; --i, --t)
{
if((bit + i) >= eit)
if (i >= sourceLen)
return eit;

while((c = *(bit + i)) != pWord[t])
{
i += std::max(bLen-t, shift[c]);
if((bit + i) >= eit) return eit;
if (i >= sourceLen) return eit;
t = bLen-1;
}
}
Expand Down