mirror of
https://github.com/thunderbrewhq/common.git
synced 2025-12-12 11:12:29 +00:00
fix(datastore): correctly handle null terminated strings
This commit is contained in:
parent
d1e4812aa3
commit
156ccfdb7d
2 changed files with 21 additions and 3 deletions
|
|
@ -159,6 +159,10 @@ CDataStore& CDataStore::GetString(char* val, uint32_t maxChars) {
|
|||
STORM_ASSERT(this->IsFinal());
|
||||
STORM_ASSERT(val || maxChars == 0);
|
||||
|
||||
if (maxChars == 0) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (this->FetchRead(this->m_read, 1)) {
|
||||
auto ofs = this->m_read - this->m_base;
|
||||
auto ptr = &this->m_data[ofs];
|
||||
|
|
@ -168,7 +172,7 @@ CDataStore& CDataStore::GetString(char* val, uint32_t maxChars) {
|
|||
val[i] = *reinterpret_cast<char*>(&ptr[i]);
|
||||
}
|
||||
|
||||
this->m_read += i;
|
||||
this->m_read += i == maxChars ? i : i + 1;
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
|
@ -316,7 +320,7 @@ CDataStore& CDataStore::PutData(const void* val, uint32_t bytes) {
|
|||
|
||||
CDataStore& CDataStore::PutString(const char* val) {
|
||||
auto len = SStrLen(val);
|
||||
return this->PutArray(reinterpret_cast<const uint8_t*>(val), len);
|
||||
return this->PutArray(reinterpret_cast<const uint8_t*>(val), len + 1);
|
||||
}
|
||||
|
||||
void CDataStore::Reset() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue