[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH] lib/uknetdev: Avoid signed and unsigned comparison



Avoids the warning 'comparison between signed and unsigned integer
expressions' in `netbuf.c`. The compiler is implicitly a substraction
between two uint16_t upcasting to int. Normally, overflows could
happen but not in this particular case.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 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.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.