Skip to content

Commit c69c7e2

Browse files
authored
Reduce warnings relevant to Zephyr platform (#4658)
This PR is intended to remove following warnings, when build in Zephyr application: wasm-micro-runtime/core/shared/platform/zephyr/platform_internal.h:293: warning: "CLOCK_MONOTONIC" redefined 293 | #define CLOCK_MONOTONIC 4 wasm-micro-runtime/core/shared/platform/zephyr/zephyr_file.c: In function 'zephyr_fs_alloc_obj': wasm-micro-runtime/core/shared/platform/zephyr/zephyr_file.c:123:25: warning: implicit declaration of function 'bh_strdup' [-Wimplicit-function-declaration] 123 | ptr->path = bh_strdup(path); | ^~~~~~~~~ wasm-micro-runtime/core/shared/platform/zephyr/zephyr_file.c:123:23: warning: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion] 123 | ptr->path = bh_strdup(path); | ^ wasm-micro-runtime/core/shared/platform/zephyr/zephyr_file.c: In function 'os_renameat': wasm-micro-runtime/core/shared/platform/zephyr/zephyr_file.c:853:35: warning: initialization of 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion] 853 | char *new_path_copy = bh_strdup(new_path); | ^~~~~~~~~ [45/462] Building C object CMakeFiles/app.dir/wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c.obj wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c: In function 'wasmtime_ssp_poll_oneoff': wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2216:42: warning: initialization of 'os_file_handle' {aka 'struct zephyr_handle *'} from 'int' makes pointer from integer without a cast [-Wint-conversion] 2216 | os_file_handle tfd = fos[i]->file_handle->fd; | ^~~ wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2222:31: warning: initialization of 'int' from 'os_file_handle' {aka 'struct zephyr_handle *'} makes integer from pointer without a cast [-Wint-conversion] 2222 | .fd = tfd, | ^~~ wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2222:31: note: (near initialization for '(anonymous).fd') --------- Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
1 parent aeec8a7 commit c69c7e2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

core/shared/platform/zephyr/zephyr_file.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,15 @@ zephyr_fs_alloc_obj(bool is_dir, const char *path, int *index)
120120
ptr = &desc_array[i];
121121
ptr->used = true;
122122
ptr->is_dir = is_dir;
123-
ptr->path = bh_strdup(path);
124123
ptr->dir_index = 0;
124+
size_t path_len = strlen(path) + 1;
125+
ptr->path = BH_MALLOC(path_len);
125126
if (ptr->path == NULL) {
126127
ptr->used = false;
127128
k_mutex_unlock(&desc_array_mutex);
128129
return NULL;
129130
}
131+
strcpy(ptr->path, path);
130132
*index = i + 3;
131133
break;
132134
}
@@ -851,11 +853,17 @@ os_renameat(os_file_handle old_handle, const char *old_path,
851853
for (int i = 0; i < CONFIG_WASI_MAX_OPEN_FILES; i++) {
852854
struct zephyr_fs_desc *ptr = &desc_array[i];
853855
if (ptr->used && ptr->path && strcmp(ptr->path, abs_old_path) == 0) {
854-
char *new_path_copy = bh_strdup(new_path);
856+
size_t new_path_len = strlen(abs_new_path) + 1;
857+
char *new_path_copy = BH_MALLOC(new_path_len);
855858
if (new_path_copy != NULL) {
859+
strcpy(new_path_copy, abs_new_path);
856860
BH_FREE(ptr->path);
857861
ptr->path = new_path_copy;
858862
}
863+
else {
864+
k_mutex_unlock(&desc_array_mutex);
865+
return __WASI_ENOMEM;
866+
}
859867
break; // Only one descriptor should match
860868
}
861869
}
@@ -1196,4 +1204,4 @@ bool
11961204
os_is_stderr_handle(os_file_handle handle)
11971205
{
11981206
return (handle == (os_file_handle)stderr);
1199-
}
1207+
}

0 commit comments

Comments
 (0)