Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

some buffer including '\0' cannot be calculated true hash value #1

@leeqwind

Description

@leeqwind

some buffer including '\0' - such as "The apple is\0 delicious!" - cannot be calculated true hash value by myWrapper->getHashFromString() function. It will only calculate hashes for "The apple is" substring because std::string constructor cut off the buffer when it meet '\0'. Then the text.length() would also be wrong, because std::string cannot calculate the correct length of the buffer.

Who know more about the bufferlen than the caller?

A little bit better solution is:

virtual std::string getHashFromString(const char* text, unsigned long textlen)
{
resetContext();
updateContext((unsigned char*)text, textlen);
return this->hashIt();
}

use LPCSTR pointer to transmit buffer parameter and the length of the buffer. The length is gaven by the caller, and it needn't construct a std::string object in runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions