Skip to content

Commit 9e7c67f

Browse files
kr-tcasaroli
authored andcommitted
clean(zephyr): reduce warnings on zephyr platform (bytecodealliance#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 f6bb665 commit 9e7c67f

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

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
@@ -622,8 +622,9 @@ os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
622622

623623
total_read += bytes_read;
624624

625-
// If we read less than we asked for, stop reading
626-
if (bytes_read < iov[i].buf_len) {
625+
/* If we read less than we asked for, stop reading
626+
bytes_read being a non-negative value was already checked */
627+
if ((size_t)bytes_read < iov[i].buf_len) {
627628
break;
628629
}
629630
}
@@ -658,8 +659,9 @@ os_pwritev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
658659

659660
total_written += bytes_written;
660661

661-
// If we wrote less than we asked for, stop writing
662-
if (bytes_written < iov[i].buf_len) {
662+
/* If we wrote less than we asked for, stop writing
663+
bytes_read being a non-negative value was already checked */
664+
if ((size_t)bytes_written < iov[i].buf_len) {
663665
break;
664666
}
665667
}
@@ -688,8 +690,9 @@ os_readv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
688690

689691
total_read += bytes_read;
690692

691-
// If we read less than we asked for, stop reading
692-
if (bytes_read < iov[i].buf_len) {
693+
/* If we read less than we asked for, stop reading
694+
bytes_read being a non-negative value was already checked */
695+
if ((size_t)bytes_read < iov[i].buf_len) {
693696
break;
694697
}
695698
}
@@ -733,8 +736,9 @@ os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
733736

734737
total_written += bytes_written;
735738

736-
// If we wrote less than we asked for, stop writing
737-
if (bytes_written < iov[i].buf_len) {
739+
/* If we wrote less than we asked for, stop writing
740+
bytes_read being a non-negative value was already checked */
741+
if ((size_t)bytes_written < iov[i].buf_len) {
738742
break;
739743
}
740744
}

0 commit comments

Comments
 (0)