mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-12 13:00:32 +00:00
Fix NULL-terminating serialise of rdctype::str adding 0 into elems
* The +1 for internal NULL terminator must be done internally, otherwise we end up with "foobar" being a 7-character string of "foobar\0". If this is then re-serialised we add more and more null terminators.
This commit is contained in:
@@ -226,6 +226,24 @@ struct str : public rdctype::array<char>
|
||||
return *this;
|
||||
}
|
||||
|
||||
void assign(const char *const in, int32_t inCount)
|
||||
{
|
||||
Delete();
|
||||
count = inCount;
|
||||
if(inCount == 0)
|
||||
{
|
||||
elems = (char *)allocate(sizeof(char));
|
||||
elems[0] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
elems = (char *)allocate(sizeof(char) * (inCount + 1));
|
||||
if(in)
|
||||
memcpy(elems, in, sizeof(char) * inCount);
|
||||
elems[count] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
operator const char *() const { return elems ? elems : ""; }
|
||||
const char *c_str() const { return elems ? elems : ""; }
|
||||
};
|
||||
|
||||
@@ -506,10 +506,9 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
create_array_uninit(el, sz + 1);
|
||||
el.assign(NULL, sz);
|
||||
for(int32_t i = 0; i < sz; i++)
|
||||
Serialise("", el.elems[i]);
|
||||
el.elems[sz] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user