savevm: fix compiler warning
PATCH 1/1 savevm: fix compiler warning
If we have a 32-bit long then the truncation of a 64-bit value will produce a compiler warning unless we make an explicit cast.
--- savevm.c | 2 +-
1 ficheiro modificado, 1 adição(+), 1 eliminado(-)
savevm.c +1 -1
@@ -2473,7 +2473,7 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,/* word at a time for speed, use of 32-bit long okay */ if (!res) {/* truncation to 32-bit long okay */ -long mask =0x0101010101010101ULL ; +long mask = (long )0x0101010101010101ULL ;while (i < slen) { xor = *(long *)(old_buf + i) ^ *(long *)(new_buf + i);if ((xor - mask) & ~xor & (mask <<7 )) {
Signature · 1 line
1.7.10.4
Quoted 11 lines · Alberto Garcia
If we have a 32-bit long then the truncation of a 64-bit value will produce a compiler warning unless we make an explicit cast.
--- savevm.c | 2 +-1 ficheiro modificado, 1 adição(+), 1 eliminado(-)
savevm.c +0
-0
savevm.c int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen, · line 2476
Quoted 5 lines
savevm.c +1
-1@@ -2473,7 +2473,7 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,/* word at a time for speed, use of 32-bit long okay */ if (!res) {/* truncation to 32-bit long okay */ -long mask =0x0101010101010101ULL ; +long mask = (long )0x0101010101010101ULL ;
C99 6.3.1.3 Signed and unsigned integers, paragraph 3:
"Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised."
The safe way of doing this is by casting to (unsigned long) instead:
"Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type."
Stefan