[Spice-devel] [PATCH spice-common 3/7] codegen: Use a better type for pointer converted to integer

Frediano Ziglio fziglio at redhat.com
Mon Feb 18 16:01:25 UTC 2019


Although on the platform we support size_t and uintptr_t are
the same on some platform the size_t can (in theory) be smaller
than the necessary integer to store a pointer.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 python_modules/demarshal.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py
index 36213b1..68532a9 100644
--- a/python_modules/demarshal.py
+++ b/python_modules/demarshal.py
@@ -847,7 +847,7 @@ def write_array_parser(writer, member, nelements, array, dest, scope):
                     write_container_parser(writer, element_type, dest2)
                 if array.has_attr("ptr_array"):
                     writer.comment("Align ptr_array element to 4 bytes").newline()
-                    writer.assign("end", "(uint8_t *)SPICE_ALIGN((size_t)end, 4)")
+                    writer.assign("end", "(uint8_t *)SPICE_ALIGN((uintptr_t)end, 4)")
 
 def write_parse_pointer_core(writer, target_type, offset, at_end, dest, member_name, scope):
     writer.assign("ptr_info[n_ptr].offset", offset)
@@ -968,7 +968,7 @@ def write_ptr_info_check(writer):
                 writer.assign("*%s" % dest, "NULL")
             with writer.block(" else"):
                 writer.comment("Align to 32 bit").newline()
-                writer.assign("end", "(uint8_t *)SPICE_ALIGN((size_t)end, 4)")
+                writer.assign("end", "(uint8_t *)SPICE_ALIGN((uintptr_t)end, 4)")
                 writer.assign("*%s" % dest, "(void *)end")
                 writer.assign("end", "%s(message_start, message_end, end, &ptr_info[%s])" % (function, index))
                 writer.error_check("end == NULL")
-- 
2.20.1



More information about the Spice-devel mailing list