Skip to content

Commit

Permalink
Fix memcpy to nullptr (commit 7e43168)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamahen committed Dec 21, 2023
1 parent b993543 commit e77521a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions libhdt/src/libdcs/CSD_HTFC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Miguel A. Martinez-Prieto: [email protected]
*/

#include <string>
#include "CSD_HTFC.h"

#if HAVE_CDS
Expand Down Expand Up @@ -57,8 +58,9 @@ CSD_HTFC::CSD_HTFC(hdt::IteratorUCharString *it, uint32_t blocksize,

vector<uint> xblocks; // Temporal storage for start positions

unsigned char *previousStr = NULL, *currentStr = NULL;
uint previousLength = 0, currentLength = 0;
std::basic_string<unsigned char> previousStr((const unsigned char*)"");
unsigned char *currentStr = NULL;
uint currentLength = 0;

while (it->hasNext()) {
currentStr = it->next();
Expand Down Expand Up @@ -99,8 +101,8 @@ CSD_HTFC::CSD_HTFC(hdt::IteratorUCharString *it, uint32_t blocksize,
// Regular string

// Calculating the length of the long common prefix
uint delta = longest_common_prefix(previousStr, currentStr,
previousLength, currentLength);
uint delta = longest_common_prefix(previousStr.data(), currentStr,
previousStr.length(), currentLength);

// cout << "Block: " << nblocks << " Pos: "<< length << endl;
// cout << previousStr << endl << currentStr << endl << " Delta: " <<
Expand All @@ -121,8 +123,7 @@ CSD_HTFC::CSD_HTFC(hdt::IteratorUCharString *it, uint32_t blocksize,

// New string processed
numstrings++;
memcpy(previousStr, currentStr, currentLength);
previousLength = currentLength;
previousStr.assign(currentStr, currentLength);

it->freeStr(currentStr);
// NOTIFYCOND(listener, "Converting dictionary to HTFC", length,
Expand Down

0 comments on commit e77521a

Please sign in to comment.