Просмотр исходного кода

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>
Krisztian 19 часов назад
Родитель
Сommit
c69c7e2261
1 измененных файлов с 11 добавлено и 3 удалено
  1. 11 3
      core/shared/platform/zephyr/zephyr_file.c

+ 11 - 3
core/shared/platform/zephyr/zephyr_file.c

@@ -120,13 +120,15 @@ zephyr_fs_alloc_obj(bool is_dir, const char *path, int *index)
             ptr = &desc_array[i];
             ptr->used = true;
             ptr->is_dir = is_dir;
-            ptr->path = bh_strdup(path);
             ptr->dir_index = 0;
+            size_t path_len = strlen(path) + 1;
+            ptr->path = BH_MALLOC(path_len);
             if (ptr->path == NULL) {
                 ptr->used = false;
                 k_mutex_unlock(&desc_array_mutex);
                 return NULL;
             }
+            strcpy(ptr->path, path);
             *index = i + 3;
             break;
         }
@@ -851,11 +853,17 @@ os_renameat(os_file_handle old_handle, const char *old_path,
     for (int i = 0; i < CONFIG_WASI_MAX_OPEN_FILES; i++) {
         struct zephyr_fs_desc *ptr = &desc_array[i];
         if (ptr->used && ptr->path && strcmp(ptr->path, abs_old_path) == 0) {
-            char *new_path_copy = bh_strdup(new_path);
+            size_t new_path_len = strlen(abs_new_path) + 1;
+            char *new_path_copy = BH_MALLOC(new_path_len);
             if (new_path_copy != NULL) {
+                strcpy(new_path_copy, abs_new_path);
                 BH_FREE(ptr->path);
                 ptr->path = new_path_copy;
             }
+            else {
+                k_mutex_unlock(&desc_array_mutex);
+                return __WASI_ENOMEM;
+            }
             break; // Only one descriptor should match
         }
     }
@@ -1196,4 +1204,4 @@ bool
 os_is_stderr_handle(os_file_handle handle)
 {
     return (handle == (os_file_handle)stderr);
-}
+}