mirror of
https://github.com/apache/nuttx.git
synced 2026-08-08 05:57:16 +00:00
arch/common: fix host_flags_to_mode() O_RDONLY sentinel collision
host_flags_to_mode() used a trailing 0 entry in modeflags[] as the loop-termination sentinel. O_RDONLY is defined as 0 and is exactly modeflags[1], so the loop's termination check fired before ever comparing that entry, and a bare O_RDONLY open always fell through to -EINVAL. Bound the loop by array size (nitems()) instead of a value sentinel. Signed-off-by: liang.huang <liang.huang@houmo.ai>
This commit is contained in:
parent
2af63e91b9
commit
335aacbf1a
3 changed files with 6 additions and 6 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
@ -94,11 +95,10 @@ static int host_flags_to_mode(int flags)
|
|||
O_WRONLY | O_CREAT | O_APPEND,
|
||||
O_RDWR | O_CREAT | O_APPEND | O_TEXT,
|
||||
O_RDWR | O_CREAT | O_APPEND,
|
||||
0,
|
||||
};
|
||||
|
||||
int i;
|
||||
for (i = 0; modeflags[i] != 0; i++)
|
||||
for (i = 0; i < nitems(modeflags); i++)
|
||||
{
|
||||
if ((modemasks & flags) == modeflags[i])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
@ -94,11 +95,10 @@ static int host_flags_to_mode(int flags)
|
|||
O_WRONLY | O_CREAT | O_APPEND,
|
||||
O_RDWR | O_CREAT | O_APPEND | O_TEXT,
|
||||
O_RDWR | O_CREAT | O_APPEND,
|
||||
0,
|
||||
};
|
||||
|
||||
int i;
|
||||
for (i = 0; modeflags[i] != 0; i++)
|
||||
for (i = 0; i < nitems(modeflags); i++)
|
||||
{
|
||||
if ((modemasks & flags) == modeflags[i])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include <syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
@ -94,11 +95,10 @@ static int host_flags_to_mode(int flags)
|
|||
O_WRONLY | O_CREAT | O_APPEND,
|
||||
O_RDWR | O_CREAT | O_APPEND | O_TEXT,
|
||||
O_RDWR | O_CREAT | O_APPEND,
|
||||
0,
|
||||
};
|
||||
|
||||
int i;
|
||||
for (i = 0; modeflags[i] != 0; i++)
|
||||
for (i = 0; i < nitems(modeflags); i++)
|
||||
{
|
||||
if ((modemasks & flags) == modeflags[i])
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue