@@ -54,7 +54,7 @@ CSD_FMIndex::CSD_FMIndex(hdt::IteratorUCharString *it, bool sparse_bitsequence,
5454
5555 this ->type = FMINDEX;
5656 string element;
57- unsigned char *text;
57+ unsigned char *text; // TODO: std::vector<unsigned char>
5858 uint *bitmap = 0 ;
5959 // uint32_t *bitmap = 0;
6060
@@ -90,7 +90,7 @@ CSD_FMIndex::CSD_FMIndex(hdt::IteratorUCharString *it, bool sparse_bitsequence,
9090 // Checking the current size of the encoded
9191 // sequence: realloc if necessary
9292 if ((total + currentLength + 1 ) > reservedSize) {
93- while ((( size_t ) total + currentLength + 1 ) > reservedSize) {
93+ while ((total + currentLength + 1 ) > reservedSize) {
9494 reservedSize <<= 1 ;
9595 if (reservedSize == 0 ) {
9696 reservedSize = ((size_t )total + currentLength) * 2 ;
@@ -99,7 +99,7 @@ CSD_FMIndex::CSD_FMIndex(hdt::IteratorUCharString *it, bool sparse_bitsequence,
9999 text =
100100 (unsigned char *)realloc (text, reservedSize * sizeof (unsigned char ));
101101 }
102- strncpy ((char *)(text + total), (char *)currentStr, currentLength );
102+ strncpy ((char *)(text + total), (char *)currentStr, reservedSize - total );
103103
104104 total += currentLength;
105105
@@ -118,7 +118,7 @@ CSD_FMIndex::CSD_FMIndex(hdt::IteratorUCharString *it, bool sparse_bitsequence,
118118 textFinal = new char [total + 1 ];
119119 // cout<<"testing:total cpy:"<<total<<endl;
120120 // cout<<"testing:text:"<<text<<endl;
121- strncpy ((char *)(textFinal), (char *)text, total);
121+ strncpy ((char *)(textFinal), (char *)text, total + 1 );
122122 textFinal[total] = ' \0 ' ; // end of the text
123123 // cout<<"testing:textFinal:"<<textFinal<<endl;
124124
@@ -149,7 +149,7 @@ CSD_FMIndex::CSD_FMIndex(hdt::IteratorUCharString *it, bool sparse_bitsequence,
149149 separators = new BitSequenceRG (bitmap, len, 4 );
150150 delete[] bitmap;
151151 }
152- delete[] text;
152+ free ( text) ;
153153}
154154
155155void CSD_FMIndex::build_ssa (unsigned char *text, size_t len,
0 commit comments