Skip to content

Commit ca88810

Browse files
committed
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.
1 parent c898fc6 commit ca88810

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

renderdoc/api/replay/basic_types.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,24 @@ struct str : public rdctype::array<char>
226226
return *this;
227227
}
228228

229+
void assign(const char *const in, int32_t inCount)
230+
{
231+
Delete();
232+
count = inCount;
233+
if(inCount == 0)
234+
{
235+
elems = (char *)allocate(sizeof(char));
236+
elems[0] = 0;
237+
}
238+
else
239+
{
240+
elems = (char *)allocate(sizeof(char) * (inCount + 1));
241+
if(in)
242+
memcpy(elems, in, sizeof(char) * inCount);
243+
elems[count] = 0;
244+
}
245+
}
246+
229247
operator const char *() const { return elems ? elems : ""; }
230248
const char *c_str() const { return elems ? elems : ""; }
231249
};

renderdoc/serialise/serialiser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,9 @@ class Serialiser
506506
}
507507
else
508508
{
509-
create_array_uninit(el, sz + 1);
509+
el.assign(NULL, sz);
510510
for(int32_t i = 0; i < sz; i++)
511511
Serialise("", el.elems[i]);
512-
el.elems[sz] = 0;
513512
}
514513
}
515514

0 commit comments

Comments
 (0)