This is an automated email from the ASF dual-hosted git repository.

masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f5e6bd383 hostfs: mask bit fields of not support
7f5e6bd383 is described below

commit 7f5e6bd3832e391a86036a959eeb76fcc9967eed
Author: wanggang26 <wanggan...@xiaomi.com>
AuthorDate: Fri Sep 22 21:20:39 2023 +0800

    hostfs: mask bit fields of not support
    
    Signed-off-by: wanggang26 <wanggan...@xiaomi.com>
---
 arch/arm/src/common/arm_hostfs.c      | 4 +++-
 arch/arm64/src/common/arm64_hostfs.c  | 4 +++-
 arch/risc-v/src/common/riscv_hostfs.c | 4 +++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/arm/src/common/arm_hostfs.c b/arch/arm/src/common/arm_hostfs.c
index 8e6ae5ee66..b83b59ce4d 100644
--- a/arch/arm/src/common/arm_hostfs.c
+++ b/arch/arm/src/common/arm_hostfs.c
@@ -76,6 +76,8 @@ static ssize_t host_flen(long fd)
 
 static int host_flags_to_mode(int flags)
 {
+  static const int modemasks = O_RDONLY | O_WRONLY | O_TEXT | O_RDWR |
+                               O_CREAT | O_TRUNC | O_APPEND;
   static const int modeflags[] =
   {
     O_RDONLY | O_TEXT,
@@ -96,7 +98,7 @@ static int host_flags_to_mode(int flags)
   int i;
   for (i = 0; modeflags[i] != 0; i++)
     {
-      if (modeflags[i] == flags)
+      if ((modemasks & flags) == modeflags[i])
         {
           return i;
         }
diff --git a/arch/arm64/src/common/arm64_hostfs.c 
b/arch/arm64/src/common/arm64_hostfs.c
index d0c8217e2c..3bc0c20f5c 100644
--- a/arch/arm64/src/common/arm64_hostfs.c
+++ b/arch/arm64/src/common/arm64_hostfs.c
@@ -76,6 +76,8 @@ static ssize_t host_flen(long fd)
 
 static int host_flags_to_mode(int flags)
 {
+  static const int modemasks = O_RDONLY | O_WRONLY | O_TEXT | O_RDWR |
+                               O_CREAT | O_TRUNC | O_APPEND;
   static const int modeflags[] =
   {
     O_RDONLY | O_TEXT,
@@ -96,7 +98,7 @@ static int host_flags_to_mode(int flags)
   int i;
   for (i = 0; modeflags[i] != 0; i++)
     {
-      if (modeflags[i] == flags)
+      if ((modemasks & flags) == modeflags[i])
         {
           return i;
         }
diff --git a/arch/risc-v/src/common/riscv_hostfs.c 
b/arch/risc-v/src/common/riscv_hostfs.c
index 2bb940ce6d..0e5687ebfb 100644
--- a/arch/risc-v/src/common/riscv_hostfs.c
+++ b/arch/risc-v/src/common/riscv_hostfs.c
@@ -76,6 +76,8 @@ static ssize_t host_flen(long fd)
 
 static int host_flags_to_mode(int flags)
 {
+  static const int modemasks = O_RDONLY | O_WRONLY | O_TEXT | O_RDWR |
+                               O_CREAT | O_TRUNC | O_APPEND;
   static const int modeflags[] =
   {
     O_RDONLY | O_TEXT,
@@ -96,7 +98,7 @@ static int host_flags_to_mode(int flags)
   int i;
   for (i = 0; modeflags[i] != 0; i++)
     {
-      if (modeflags[i] == flags)
+      if ((modemasks & flags) == modeflags[i])
         {
           return i;
         }

Reply via email to