Anda
Anda

Reputation: 710

Exception: std::length_error at memory location 0x00CFEC24

This is one of my methods and the hash works and is assigned correctly but right before it exits the function ,"blockHash" becomes "" and it gives me the above error.

Block::Block(int index, const double amount, const std::string& senderKey, 
const std::string& 
receiverKey, const std::string& prevHash, time_t timestamp)
:nrTransactions(0)
{
std::string str = std::to_string(amount);
this->blockHash = generateHash(str);
}

This is the function that seems to be the problem:

std::string& Block::generateHash(const std::string& str)
{
std::string hash = sha256(str);
return hash;
}

For the first block i made amount "0".

Upvotes: 0

Views: 792

Answers (1)

shanker861
shanker861

Reputation: 619

You are returning reference to local variable. That is definitely problem. change the return type to std::string

 std::string Block::generateHash(const std::string& str)
 {
     std::string hash = sha256(str);
     return hash;
 }

Upvotes: 4

Related Questions