summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Harris <pharris@opentext.com>2010-09-22 21:16:51 -0400
committerPeter Harris <pharris@opentext.com>2010-09-22 22:20:04 -0400
commit8c1d2021ca611c1452a8d2ff2a705569e4ebd056 (patch)
treebedc854356471d9b286f410f28042dda1af1f802
parent28a71c6567d08272dc9c1c2b32f0529f11f62b9e (diff)
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>
-rw-r--r--src/c_client.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/c_client.py b/src/c_client.py
index 08d6ec4..a66c7e3 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -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;')