Parcourir la source

clean(zephyr): reduce warnings on zephyr platform (#4860)

* clean(warnings): fix [-Wsign-compare] in zephyr_file

buf_len is a long unsigned int, while bytes_* can be negative due to error values.
We don't need to check bytes_* for negative value, as it was done during read/write op.

* clean(warnings): fix "MIN" redefined warning

Some platforms, like Zephyr, already define MIN and definition in WAMR cause
`warning: "MIN" redefined` warning.
Check if it was defined before, and do not redefine it.

Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
Krisztian il y a 1 jour
Parent
commit
fa7c2d37f4

+ 3 - 0
core/iwasm/libraries/lib-wasi-threads/tid_allocator.c

@@ -8,7 +8,10 @@
 #include "bh_log.h"
 
 bh_static_assert(TID_MIN <= TID_MAX);
+/* Some platforms, like Zephyr, have already defined MIN at this point */
+#ifndef MIN
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
 
 bool
 tid_allocator_init(TidAllocator *tid_allocator)

+ 12 - 8
core/shared/platform/zephyr/zephyr_file.c

@@ -594,8 +594,9 @@ os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
 
         total_read += bytes_read;
 
-        // If we read less than we asked for, stop reading
-        if (bytes_read < iov[i].buf_len) {
+        /*  If we read less than we asked for, stop reading
+            bytes_read being a non-negative value was already checked */
+        if ((size_t)bytes_read < iov[i].buf_len) {
             break;
         }
     }
@@ -630,8 +631,9 @@ os_pwritev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
 
         total_written += bytes_written;
 
-        // If we wrote less than we asked for, stop writing
-        if (bytes_written < iov[i].buf_len) {
+        /*  If we wrote less than we asked for, stop writing
+            bytes_read being a non-negative value was already checked */
+        if ((size_t)bytes_written < iov[i].buf_len) {
             break;
         }
     }
@@ -660,8 +662,9 @@ os_readv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
 
         total_read += bytes_read;
 
-        // If we read less than we asked for, stop reading
-        if (bytes_read < iov[i].buf_len) {
+        /*  If we read less than we asked for, stop reading
+            bytes_read being a non-negative value was already checked */
+        if ((size_t)bytes_read < iov[i].buf_len) {
             break;
         }
     }
@@ -705,8 +708,9 @@ os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
 
         total_written += bytes_written;
 
-        // If we wrote less than we asked for, stop writing
-        if (bytes_written < iov[i].buf_len) {
+        /*  If we wrote less than we asked for, stop writing
+            bytes_read being a non-negative value was already checked */
+        if ((size_t)bytes_written < iov[i].buf_len) {
             break;
         }
     }