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 @@
* CyclicString.cpp
*
* Created on: Nov 23, 2013
* Author: Jan Travnicek
* Author: Jan Travnicek
*/
 
#include "CyclicString.h"
......@@ -90,40 +90,40 @@ void CyclicString::setContent(std::vector<alphabet::Symbol> data) {
if(unknownSymbols.size() > 0)
throw exception::AlibException("Input symbols not in the alphabet.");
 
/**
* Lexicographically least circular substrings
* Kellogg S. Booth
* 1979
*/
int* f = new int[data.size()]; /** Knuth–Morris–Pratt like array */
int k = 0; /** Least circular string shift value */
int i;
f[0]=-1;
for (unsigned j = 1; j < 2*data.size(); ++j) {
/** condition adjusted by Radomír Polách, >= is not correct */
if (j - k > data.size()) break;
i = f[j - k -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;
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()]) k = j;
f[j - k] = -1;
} else f[j - k] = i+1;
}
delete [] f;
if (k == 0) {
m_Data = data;
return;
}
std::vector<alphabet::Symbol> tmp;
for (unsigned l = k; l < data.size() + k; ++l) {
tmp.push_back(std::move(data[l % data.size()]));
}
m_Data = tmp;
/**
* Lexicographically least circular substrings
* Kellogg S. Booth
* 1979
*/
int* f = new int[data.size() + 1]; /** Knuth–Morris–Pratt like array */
int k = 0; /** Least circular string shift value */
int i;
f[0] = -1;
for (unsigned j = 1; j < 2 * data.size(); ++j) {
/** condition adjusted by Radomír Polách, >= is not correct */
if (j - k > data.size()) break;
i = f[j - k - 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;
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()]) k = j;
f[j - k] = -1;
} else f[j - k] = i + 1;
}
delete [] f;
if (k == 0) {
m_Data = data;
return;
}
std::vector<alphabet::Symbol> tmp;
for (unsigned l = k; l < data.size() + k; ++l) {
tmp.push_back(std::move(data[l % data.size()]));
}
m_Data = tmp;
}
 
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