Skip to content

Commit d84a78d

Browse files
quic-mathbernJuan Quintela
authored andcommitted
migration/xbzrle: use ctz64 to avoid undefined result
__builtin_ctzll() produces undefined results when the argument is 0. This can be seen through test-xbzrle, which produces the following warning: ../migration/xbzrle.c:265: runtime error: passing zero to ctz(), which is not a valid argument Replace __builtin_ctzll() with our ctz64() wrapper which properly handles 0. Signed-off-by: Matheus Tavares Bernardino <[email protected]> Reviewed-by: Dr. David Alan Gilbert <[email protected]> Reviewed-by: Juan Quintela <[email protected]> Signed-off-by: Juan Quintela <[email protected]>
1 parent a538221 commit d84a78d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

migration/xbzrle.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
#include "qemu/osdep.h"
1414
#include "qemu/cutils.h"
15+
#include "qemu/host-utils.h"
1516
#include "xbzrle.h"
1617

1718
/*
@@ -233,7 +234,7 @@ int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int slen,
233234
break;
234235
}
235236
never_same = false;
236-
num = __builtin_ctzll(~comp);
237+
num = ctz64(~comp);
237238
num = (num < bytes_to_check) ? num : bytes_to_check;
238239
zrun_len += num;
239240
bytes_to_check -= num;
@@ -262,7 +263,7 @@ int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int slen,
262263
nzrun_len += 64;
263264
break;
264265
}
265-
num = __builtin_ctzll(comp);
266+
num = ctz64(comp);
266267
num = (num < bytes_to_check) ? num : bytes_to_check;
267268
nzrun_len += num;
268269
bytes_to_check -= num;

0 commit comments

Comments
 (0)