Skip to content

Commit fa7c2d3

Browse files
authored
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>
1 parent 595dcd5 commit fa7c2d3

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

core/iwasm/libraries/lib-wasi-threads/tid_allocator.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
#include "bh_log.h"
99

1010
bh_static_assert(TID_MIN <= TID_MAX);
11+
/* Some platforms, like Zephyr, have already defined MIN at this point */
12+
#ifndef MIN
1113
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
14+
#endif
1215

1316
bool
1417
tid_allocator_init(TidAllocator *tid_allocator)

core/shared/platform/zephyr/zephyr_file.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,9 @@ os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
594594

595595
total_read += bytes_read;
596596

597-
// If we read less than we asked for, stop reading
598-
if (bytes_read < iov[i].buf_len) {
597+
/* If we read less than we asked for, stop reading
598+
bytes_read being a non-negative value was already checked */
599+
if ((size_t)bytes_read < iov[i].buf_len) {
599600
break;
600601
}
601602
}
@@ -630,8 +631,9 @@ os_pwritev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
630631

631632
total_written += bytes_written;
632633

633-
// If we wrote less than we asked for, stop writing
634-
if (bytes_written < iov[i].buf_len) {
634+
/* If we wrote less than we asked for, stop writing
635+
bytes_read being a non-negative value was already checked */
636+
if ((size_t)bytes_written < iov[i].buf_len) {
635637
break;
636638
}
637639
}
@@ -660,8 +662,9 @@ os_readv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
660662

661663
total_read += bytes_read;
662664

663-
// If we read less than we asked for, stop reading
664-
if (bytes_read < iov[i].buf_len) {
665+
/* If we read less than we asked for, stop reading
666+
bytes_read being a non-negative value was already checked */
667+
if ((size_t)bytes_read < iov[i].buf_len) {
665668
break;
666669
}
667670
}
@@ -705,8 +708,9 @@ os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
705708

706709
total_written += bytes_written;
707710

708-
// If we wrote less than we asked for, stop writing
709-
if (bytes_written < iov[i].buf_len) {
711+
/* If we wrote less than we asked for, stop writing
712+
bytes_read being a non-negative value was already checked */
713+
if ((size_t)bytes_written < iov[i].buf_len) {
710714
break;
711715
}
712716
}

0 commit comments

Comments
 (0)