From 5e147f00568983357bfd49a8d797d5c7f8c7daec Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Mon, 20 Oct 2014 14:04:27 +0200
Subject: [PATCH] fix invalid write of size 4

---
 alib2data/src/string/CyclicString.cpp | 70 +++++++++++++--------------
 1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/alib2data/src/string/CyclicString.cpp b/alib2data/src/string/CyclicString.cpp
index a76bd68639..29381ccc30 100644
--- a/alib2data/src/string/CyclicString.cpp
+++ b/alib2data/src/string/CyclicString.cpp
@@ -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 {
-- 
GitLab