Bad file access mode or status
Access mode argument of function in fopen
or open
group
is invalid
Description
This defect occurs
when you use functions in the fopen
or open
group
with invalid or incompatible file access modes, file creation flags,
or file status flags as arguments. For instance, for the open
function,
examples of valid:
Access modes include
O_RDONLY
,O_WRONLY
, andO_RDWR
File creation flags include
O_CREAT
,O_EXCL
,O_NOCTTY
, andO_TRUNC
.File status flags include
O_APPEND
,O_ASYNC
,O_CLOEXEC
,O_DIRECT
,O_DIRECTORY
,O_LARGEFILE
,O_NOATIME
,O_NOFOLLOW
,O_NONBLOCK
,O_NDELAY
,O_SHLOCK
,O_EXLOCK
,O_FSYNC
,O_SYNC
and so on.
The defect can occur in the following situations.
Situation | Risk | Fix |
---|---|---|
You pass an empty or invalid access mode to the According
to the ANSI® C standard, the valid access modes for
|
Some implementations allow extension of the access mode such as:
However, your access mode string must begin with one of the valid sequences. | Pass a valid access mode to fopen . |
You pass the status flag O_APPEND to the open function
without combining it with either O_WRONLY or O_RDWR . |
The | Pass either O_APPEND|O_WRONLY or O_APPEND|O_RDWR as
access mode. |
You pass the status flags O_APPEND and O_TRUNC together
to the open function. |
The | Depending on what you intend to do, pass one of the two modes. |
You pass the status flag O_ASYNC to the open function. | On certain implementations, the mode O_ASYNC does
not enable signal-driven I/O operations. | Use the fcntl(pathname, F_SETFL, O_ASYNC); instead. |
Fix
The fix depends on the function and the flags used. See fixes in the table above and code examples with fixes below.
If you do not want to fix the issue, add comments to your result or code to avoid another review. See:
Address Results in Polyspace User Interface Through Bug Fixes or Justifications if you review results in the Polyspace user interface.
Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access) if you review results in a web browser.
Annotate Code and Hide Known or Acceptable Results if you review results in an IDE.
Examples
Result Information
Group: Programming |
Language: C | C++ |
Default: Off |
Command-Line Syntax: BAD_FILE_ACCESS_MODE_STATUS |
Impact: Medium |
Version History
Introduced in R2015b
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)