[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v3 2/2] lib/uknetdev: Fix compliation warning about signed/unsigned comparision
This fixes the compilation warning when compiling libuknetdev /root/hj/UK/unikraft/lib/uknetdev/netbuf.c: In function 'uk_netbuf_alloc_buf': /root/hj/UK/unikraft/lib/uknetdev/netbuf.c:120:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (likely(UINT16_MAX - headroom > NETBUF_ADDR_ALIGNMENT)) { ^ /root/hj/UK/unikraft/include/uk/arch/lcpu.h:48:43: note: in definition of macro 'likely' #define likely(x) (__builtin_expect((!!(x)), 1)) ^ The UINT16_MAX is 0xffff (signed int) on my X86 host (gcc version 7.4.0). Integer types smaller than int are promoted when an operation is performed on them. Thus, the left side of equation is "int", and the right side is size_t. Signed-off-by: Jia He <justin.he@xxxxxxx> --- lib/uknetdev/netbuf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/uknetdev/netbuf.c b/lib/uknetdev/netbuf.c index 96a5f68..bd39c54 100644 --- a/lib/uknetdev/netbuf.c +++ b/lib/uknetdev/netbuf.c @@ -117,7 +117,7 @@ struct uk_netbuf *uk_netbuf_alloc_buf(struct uk_alloc *a, size_t buflen, * We can only do this if the given headroom stays within * uint16_t bounds after the operation. */ - if (likely(UINT16_MAX - headroom > NETBUF_ADDR_ALIGNMENT)) { + if (likely((size_t)(UINT16_MAX - headroom) > NETBUF_ADDR_ALIGNMENT)) { if (privlen == 0) { priv_offset = 0; buf_offset = sizeof(*m); @@ -166,7 +166,7 @@ struct uk_netbuf *uk_netbuf_prepare_buf(void *mem, size_t size, * We can only do this if the given headroom stays within * uint16_t bounds after the operation. */ - if (likely(UINT16_MAX - headroom > NETBUF_ADDR_ALIGNMENT)) { + if (likely((size_t)(UINT16_MAX - headroom) > NETBUF_ADDR_ALIGNMENT)) { if (privlen == 0) { priv_offset = 0; buf_offset = sizeof(*m); -- 2.17.1 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |