Make *_unserialize safe to use on buffers in-place
authorPeter Harris <pharris@opentext.com>
Thu, 23 Sep 2010 01:16:51 +0000 (21:16 -0400)
committerPeter Harris <pharris@opentext.com>
Thu, 23 Sep 2010 02:20:04 +0000 (22:20 -0400)
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>
src/c_client.py

index 08d6ec4..a66c7e3 100644 (file)
@@ -1218,12 +1218,13 @@ def _c_serialize(context, self):
             
         # unserialize: assign variable size fields individually
         if 'unserialize' == context:
             
         # 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():
             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;')
  
     _c('')
     _c('    return xcb_buffer_len;')