From 2366e8c4932fb0be41a973b9a5eb7add52a9fdaa Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 18 Apr 2022 17:54:15 +0900 Subject: [PATCH] Fix a few signedness warnings (#1095) Fix compile warnings in libc-wasi posix.c: ``` posix.c:880:41: warning: comparison of integers of different signs: 'unsigned long' and 'ssize_t' (aka 'long') [-Wsign-compare] if (bufoff + iov[i].buf_len < len) { posix.c:1359:32: warning: comparison of integers of different signs: 'off_t' (aka 'long long') and 'unsigned long long' [-Wsign-compare] if (ret == 0 && sb.st_size < offset + len) ``` --- .../libc-wasi/sandboxed-system-primitives/src/posix.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index d706c7ad..46d567e5 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -877,7 +877,7 @@ wasmtime_ssp_fd_pread( // Copy data back to vectors. size_t bufoff = 0; for (size_t i = 0; i < iovcnt; ++i) { - if (bufoff + iov[i].buf_len < len) { + if (bufoff + iov[i].buf_len < (size_t)len) { bh_memcpy_s(iov[i].buf, iov[i].buf_len, buf + bufoff, iov[i].buf_len); bufoff += iov[i].buf_len; @@ -1356,8 +1356,9 @@ wasmtime_ssp_fd_allocate( // conditions. We may end up shrinking the file right now. struct stat sb; int ret = fstat(fd_number(fo), &sb); - if (ret == 0 && sb.st_size < offset + len) - ret = ftruncate(fd_number(fo), offset + len); + off_t newsize = (off_t)(offset + len); + if (ret == 0 && sb.st_size < newsize) + ret = ftruncate(fd_number(fo), newsize); #endif fd_object_release(fo);