Skip to content
Snippets Groups Projects
Commit 5e147f00 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

fix invalid write of size 4

parent 80174bd8
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* CyclicString.cpp * CyclicString.cpp
* *
* Created on: Nov 23, 2013 * Created on: Nov 23, 2013
* Author: Jan Travnicek * Author: Jan Travnicek
*/ */
   
#include "CyclicString.h" #include "CyclicString.h"
...@@ -90,40 +90,40 @@ void CyclicString::setContent(std::vector<alphabet::Symbol> data) { ...@@ -90,40 +90,40 @@ void CyclicString::setContent(std::vector<alphabet::Symbol> data) {
if(unknownSymbols.size() > 0) if(unknownSymbols.size() > 0)
throw exception::AlibException("Input symbols not in the alphabet."); throw exception::AlibException("Input symbols not in the alphabet.");
   
/** /**
* Lexicographically least circular substrings * Lexicographically least circular substrings
* Kellogg S. Booth * Kellogg S. Booth
* 1979 * 1979
*/ */
int* f = new int[data.size()]; /** Knuth–Morris–Pratt like array */ int* f = new int[data.size() + 1]; /** Knuth–Morris–Pratt like array */
int k = 0; /** Least circular string shift value */ int k = 0; /** Least circular string shift value */
int i; int i;
f[0]=-1; f[0] = -1;
for (unsigned j = 1; j < 2*data.size(); ++j) { for (unsigned j = 1; j < 2 * data.size(); ++j) {
/** condition adjusted by Radomír Polách, >= is not correct */ /** condition adjusted by Radomír Polách, >= is not correct */
if (j - k > data.size()) break; if (j - k > data.size()) break;
i = f[j - k -1]; i = f[j - k - 1];
while (data[j % data.size()] != data[(k + i + 1) % data.size()] && i != -1) { while (data[j % data.size()] != data[(k + i + 1) % data.size()] && i != -1) {
if (data[j % data.size()] < data[(k + i + 1) % data.size()]) k = j - i - 1; if (data[j % data.size()] < data[(k + i + 1) % data.size()]) k = j - i - 1;
i = f[i]; i = f[i];
} }
if (data[j % data.size()] != data[(k + i + 1) % data.size()] && i == -1) { if (data[j % data.size()] != data[(k + i + 1) % data.size()] && i == -1) {
if (data[j % data.size()] < data[(k + i + 1) % data.size()]) k = j; if (data[j % data.size()] < data[(k + i + 1) % data.size()]) k = j;
f[j - k] = -1; f[j - k] = -1;
} else f[j - k] = i+1; } else f[j - k] = i + 1;
} }
delete [] f; delete [] f;
if (k == 0) { if (k == 0) {
m_Data = data; m_Data = data;
return; return;
} }
std::vector<alphabet::Symbol> tmp; std::vector<alphabet::Symbol> tmp;
for (unsigned l = k; l < data.size() + k; ++l) { for (unsigned l = k; l < data.size() + k; ++l) {
tmp.push_back(std::move(data[l % data.size()])); tmp.push_back(std::move(data[l % data.size()]));
} }
m_Data = tmp; m_Data = tmp;
} }
   
bool CyclicString::isEmpty() const { bool CyclicString::isEmpty() const {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment