Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b9622fd
Add Os::File::open overloads for bounded char* and Fw::StringBase
devin-ai-integration[bot] Apr 9, 2026
21cf949
Fix off-by-one: use FW_FIXED_LENGTH_STRING_SIZE + 1 as buffer size bound
devin-ai-integration[bot] Apr 9, 2026
042d243
Address PR review: use ConstStringBase and FileNameStringSize
devin-ai-integration[bot] Apr 9, 2026
fcd3c2d
Add unit test rules for bounded char* and ConstStringBase open overloads
devin-ai-integration[bot] Apr 9, 2026
8ba3ff1
Add edge-case death test for unterminated path within bounds
devin-ai-integration[bot] Apr 9, 2026
464df0f
Remove death test from randomized scenarios, keep as direct test only
devin-ai-integration[bot] Apr 9, 2026
9bd554e
Fix dangling m_path pointer in OpenFileCreateString test rule
devin-ai-integration[bot] Apr 9, 2026
03863b7
Fix uniqueness loop condition to match OpenBaseRule pattern
devin-ai-integration[bot] Apr 9, 2026
33b0a78
Remove uniqueness loop from new open rules to prevent filename exhaus…
devin-ai-integration[bot] Apr 9, 2026
ebe981d
Restore uniqueness loop in new open rules to match OpenBaseRule pattern
devin-ai-integration[bot] Apr 9, 2026
02c0717
Replace uniqueness loop with early-return for new open rules
devin-ai-integration[bot] Apr 9, 2026
e7167fe
Bump MAX_FILES and gracefully handle filename exhaustion in all open …
devin-ai-integration[bot] Apr 9, 2026
354951c
Fix assert trip in unbounded open and improve assert diagnostics
devin-ai-integration[bot] Apr 9, 2026
8f9a671
Keep FileNameStringSize bound and cap test filenames to fit
devin-ai-integration[bot] Apr 9, 2026
725f665
Tighten filename cap: subtract 1 for safety margin
devin-ai-integration[bot] Apr 9, 2026
a6ada14
Bound test buffers by FileNameStringSize instead of _POSIX_PATH_MAX
devin-ai-integration[bot] Apr 10, 2026
cb9dbc4
Remove getFileSize check for too-long filename in ActiveTextLogger UT
devin-ai-integration[bot] Apr 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Os/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// \brief common function implementation for Os::File
// ======================================================================
#include <Fw/Types/Assert.hpp>
#include <Fw/Types/StringUtils.hpp>
#include <Os/File.hpp>
#include <algorithm>

Expand Down Expand Up @@ -48,8 +49,18 @@
}

File::Status File::open(const CHAR* filepath, File::Mode requested_mode, File::OverwriteType overwrite) {
FW_ASSERT(nullptr != filepath);
return this->open(filepath, static_cast<FwSizeType>(FW_FIXED_LENGTH_STRING_SIZE + 1), requested_mode, overwrite);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter requested_mode has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter overwrite has not been checked.
}

File::Status File::open(const CHAR* filepath, FwSizeType length, File::Mode requested_mode) {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

filepath uses the basic integral type char rather than a typedef with size and signedness.
return this->open(filepath, length, requested_mode, OverwriteType::NO_OVERWRITE);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter filepath has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter length has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter requested_mode has not been checked.
}

File::Status File::open(const CHAR* filepath, FwSizeType length, File::Mode requested_mode, File::OverwriteType overwrite) {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.

Check notice

Code scanning / CodeQL

Use of basic integral type Note

filepath uses the basic integral type char rather than a typedef with size and signedness.
FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
FW_ASSERT(nullptr != filepath);
FW_ASSERT(Fw::StringUtils::string_length(filepath, length) < length);
FW_ASSERT(File::Mode::OPEN_NO_MODE < requested_mode && File::Mode::MAX_OPEN_MODE > requested_mode);
FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
FW_ASSERT((0 <= overwrite) && (overwrite < OverwriteType::MAX_OVERWRITE_TYPE));
Expand All @@ -68,6 +79,14 @@
return status;
}

File::Status File::open(const Fw::StringBase& path, File::Mode requested_mode) {
return this->open(path.toChar(), static_cast<FwSizeType>(path.getCapacity()), requested_mode, OverwriteType::NO_OVERWRITE);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter path has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter requested_mode has not been checked.
}

File::Status File::open(const Fw::StringBase& path, File::Mode requested_mode, File::OverwriteType overwrite) {
return this->open(path.toChar(), static_cast<FwSizeType>(path.getCapacity()), requested_mode, overwrite);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter path has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter requested_mode has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter overwrite has not been checked.
}

void File::close() {
FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
Expand Down
66 changes: 66 additions & 0 deletions Os/File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define Os_File_hpp_

#include <Fw/FPrimeBasicTypes.hpp>
#include <Fw/Types/StringBase.hpp>
#include <Os/Os.hpp>

// Forward declaration for UTs
Expand Down Expand Up @@ -264,6 +265,51 @@ class File final : public FileInterface {
//!
Os::FileInterface::Status open(const char* path, Mode mode);

//! \brief open file with supplied path, bounded length, and mode
//!
//! Open the file passed in with the given mode. The path length is bounded by `length`.
//! Opening files with `OPEN_CREATE` mode will not clobber existing files. Use the overload
//! accepting `OverwriteType` to set overwrite flag and clobber existing files.
//!
//! It is invalid to send `nullptr` as the path.
//! It is invalid to supply `mode` as a non-enumerated value.
//! It is invalid for the path to not be null-terminated within `length` characters.
//!
//! \param path: c-string of path to open
//! \param length: bound on the path buffer size
//! \param mode: file operation mode
//! \return: status of the open
//!
Os::FileInterface::Status open(const char* path, FwSizeType length, Mode mode);

//! \brief open file with supplied StringBase path and mode
//!
//! Open the file passed in with the given mode. Opening files with `OPEN_CREATE` mode will not clobber existing
//! files. Use the overload accepting `OverwriteType` to set overwrite flag and clobber existing files.
//!
//! It is invalid to supply `mode` as a non-enumerated value.
//!
//! \param path: StringBase reference of path to open
//! \param mode: file operation mode
//! \return: status of the open
//!
Os::FileInterface::Status open(const Fw::StringBase& path, Mode mode);

//! \brief open file with supplied StringBase path, mode, and overwrite type
//!
//! Open the file passed in with the given mode. If overwrite is set to OVERWRITE, then opening files in
//! OPEN_CREATE mode will clobber existing files. Set overwrite to NO_OVERWRITE to preserve existing files.
//!
//! It is invalid to supply `mode` as a non-enumerated value.
//! It is invalid to supply `overwrite` as a non-enumerated value.
//!
//! \param path: StringBase reference of path to open
//! \param mode: file operation mode
//! \param overwrite: overwrite existing file on create
//! \return: status of the open
//!
Os::FileInterface::Status open(const Fw::StringBase& path, Mode mode, OverwriteType overwrite);

//! \brief read data from this file into supplied buffer bounded by size
//!
//! Read data from this file up to the `size` and store it in `buffer`. This version will
Expand Down Expand Up @@ -321,6 +367,26 @@ class File final : public FileInterface {
//!
Os::FileInterface::Status open(const char* path, Mode mode, OverwriteType overwrite) override;

//! \brief open file with supplied path, bounded length, mode, and overwrite type
//!
//! Open the file passed in with the given mode. The path length is bounded by `length`.
//! If overwrite is set to OVERWRITE, then opening files in OPEN_CREATE mode will clobber
//! existing files. Set overwrite to NO_OVERWRITE to preserve existing files. This is the
//! core open implementation to which all other open overloads delegate.
//!
//! It is invalid to send `nullptr` as the path.
//! It is invalid to supply `mode` as a non-enumerated value.
//! It is invalid to supply `overwrite` as a non-enumerated value.
//! It is invalid for the path to not be null-terminated within `length` characters.
//!
//! \param path: c-string of path to open
//! \param length: bound on the path buffer size
//! \param mode: file operation mode
//! \param overwrite: overwrite existing file on create
//! \return: status of the open
//!
Os::FileInterface::Status open(const char* path, FwSizeType length, Mode mode, OverwriteType overwrite);

//! \brief close the file, if not opened then do nothing
//!
//! Closes the file, if open. Otherwise this function does nothing. Delegates to the chosen implementation's
Expand Down
Loading