Make *_unserialize safe to use on buffers in-place

By calling memmove instead of memcpy, and walking the buffer backward
from the end, *_unserialize is safe to use in-place.

Signed-off-by: Peter Harris <pharris@opentext.com>
This commit is contained in:
Peter Harris 2010-09-22 21:16:51 -04:00
parent 28a71c6567
commit 8c1d2021ca

View File

@ -1218,12 +1218,13 @@ def _c_serialize(context, self):
# unserialize: assign variable size fields individually
if 'unserialize' == context:
_c(' *%s = xcb_out;', aux_ptr)
_c(' xcb_tmp = (char *)(*_aux+1);')
_c(' xcb_tmp = ((char *)*_aux)+xcb_buffer_len;')
param_fields.reverse()
for field in param_fields:
if not field.type.fixed_size():
_c(' memcpy(xcb_tmp, %s, %s_len);', field.c_field_name, field.c_field_name)
_c(' xcb_tmp += %s_len;', field.c_field_name)
_c(' xcb_tmp -= %s_len;', field.c_field_name)
_c(' memmove(xcb_tmp, %s, %s_len);', field.c_field_name, field.c_field_name)
_c(' *%s = xcb_out;', aux_ptr)
_c('')
_c(' return xcb_buffer_len;')