-
Notifications
You must be signed in to change notification settings - Fork 1
Add portable FW_UNREACHABLE macro for FW_ASSERT #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Changes from all commits
d417962
5b5e563
33f486f
3f68f25
86be044
d115a8e
de33e95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,9 +31,17 @@ void FileWorker ::cancelIn_handler(FwIndexType portNum) { | |
| } | ||
|
|
||
| void FileWorker ::readIn_handler(FwIndexType portNum, const Fw::StringBase& path, Fw::Buffer& buffer) { | ||
| FW_ASSERT(path != nullptr); | ||
| FW_ASSERT(path.length() > 0); | ||
| FW_ASSERT(buffer.getData() != nullptr); | ||
| // Validate inputs before processing file | ||
| if (path.length() == 0) { | ||
| this->log_WARNING_HI_InvalidInput(Fw::LogStringArg("readIn"), Fw::LogStringArg("empty path")); | ||
| this->readDoneOut_out(0, FW_STATUS_INVALID_INPUT, 0); | ||
| return; | ||
| } | ||
| if (!buffer.isValid()) { | ||
| this->log_WARNING_HI_InvalidInput(Fw::LogStringArg("readIn"), Fw::LogStringArg("invalid buffer")); | ||
| this->readDoneOut_out(0, FW_STATUS_INVALID_INPUT, 0); | ||
| return; | ||
| } | ||
|
|
||
| const char* const fileName = path.toChar(); | ||
| FwSizeType fileSize = 0; | ||
|
|
@@ -62,7 +70,13 @@ void FileWorker ::readIn_handler(FwIndexType portNum, const Fw::StringBase& path | |
|
|
||
| // Get filesize | ||
| Os::FileSystem::Status fsStat = Os::FileSystem::getFileSize(fileName, fileSize); | ||
| FW_ASSERT(fsStat == Os::FileSystem::OP_OK, fsStat); // file size checked with checksum | ||
| if (fsStat != Os::FileSystem::OP_OK) { | ||
| // Path is ground-controlled and the file may change between the CRC check and here | ||
| this->log_WARNING_HI_ReadFailedFileSize(fsStat); | ||
| this->readDoneOut_out(0, FW_STATUS_FAILED_FILE_SIZE, 0); | ||
| this->m_state = FW_STATE_IDLE; | ||
| return; | ||
| } | ||
|
|
||
| // Start reading | ||
| FileWorkerStatus workerStat = this->readBufferFromFile(buffer, fileName); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Pre-existing: readBufferFromFile always returns FW_STATUS_DONE_READ even on read errors The (Refers to lines 82-86) Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
@@ -73,8 +87,12 @@ void FileWorker ::readIn_handler(FwIndexType portNum, const Fw::StringBase& path | |
| } | ||
|
|
||
| void FileWorker ::verifyIn_handler(FwIndexType portNum, const Fw::StringBase& path, U32 crc) { | ||
| FW_ASSERT(path != nullptr); | ||
| FW_ASSERT(path.length() > 0); | ||
| // Validate inputs before processing file | ||
| if (path.length() == 0) { | ||
| this->log_WARNING_HI_InvalidInput(Fw::LogStringArg("verifyIn"), Fw::LogStringArg("empty path")); | ||
| this->verifyDoneOut_out(0, FW_STATUS_INVALID_INPUT, 0); | ||
| return; | ||
| } | ||
|
|
||
| const char* const fileName = path.toChar(); | ||
| FwSizeType fileSize = 0; | ||
|
|
@@ -109,10 +127,22 @@ void FileWorker ::writeIn_handler(FwIndexType portNum, | |
| Fw::Buffer& buffer, | ||
| FwSizeType offsetBytes, | ||
| bool append) { | ||
| FW_ASSERT(path != nullptr); | ||
| FW_ASSERT(path.length() > 0); | ||
| FW_ASSERT(buffer.getData() != nullptr); | ||
| FW_ASSERT(offsetBytes <= buffer.getSize()); | ||
| // Validate inputs before processing file | ||
| if (path.length() == 0) { | ||
| this->log_WARNING_HI_InvalidInput(Fw::LogStringArg("writeIn"), Fw::LogStringArg("empty path")); | ||
| this->writeDoneOut_out(0, FW_STATUS_INVALID_INPUT, 0); | ||
| return; | ||
| } | ||
| if (!buffer.isValid()) { | ||
| this->log_WARNING_HI_InvalidInput(Fw::LogStringArg("writeIn"), Fw::LogStringArg("invalid buffer")); | ||
| this->writeDoneOut_out(0, FW_STATUS_INVALID_INPUT, 0); | ||
| return; | ||
| } | ||
| if (offsetBytes > buffer.getSize()) { | ||
| this->log_WARNING_HI_InvalidInput(Fw::LogStringArg("writeIn"), Fw::LogStringArg("invalid offset")); | ||
| this->writeDoneOut_out(0, FW_STATUS_INVALID_INPUT, 0); | ||
| return; | ||
|
Comment on lines
+141
to
+144
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Edge case: offsetBytes == buffer.getSize() passes validation but triggers downstream assert In Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| } | ||
|
|
||
| char fileName[FileNameStringSize]; | ||
|
|
||
|
|
@@ -132,7 +162,13 @@ void FileWorker ::writeIn_handler(FwIndexType portNum, | |
| // NB: may count null terminator due to FPRIME/fprime-sw#57, but should still be less than FileNameStringSize in any | ||
| // case | ||
| FwSizeType length = Fw::StringUtils::string_length(path.toChar(), FileNameStringSize); | ||
| FW_ASSERT(length < FileNameStringSize && length < sizeof(fileName)); | ||
| if (length >= FileNameStringSize || length >= sizeof(fileName)) { | ||
| // Path length is ground-controlled, so an oversized path is invalid input, not a coding error. | ||
| this->log_WARNING_HI_InvalidInput(Fw::LogStringArg("writeIn"), Fw::LogStringArg("path too long")); | ||
| this->writeDoneOut_out(0, FW_STATUS_INVALID_INPUT, 0); | ||
| this->m_state = FW_STATE_IDLE; | ||
| return; | ||
| } | ||
|
|
||
| (void)Fw::StringUtils::string_copy(fileName, path.toChar(), sizeof(fileName)); | ||
| fileName[sizeof(fileName) - 1] = 0; // guarantee termination | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,8 @@ | ||||||||||||||||||||||||||||||
| module Svc { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| active component FileWorker { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| # Ports | ||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
| #Ports | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+5
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 FPP comment style change is a significant formatting regression The section header comments in Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @ Request to write to a file | ||||||||||||||||||||||||||||||
| async input port writeIn: Svc.FileWrite | ||||||||||||||||||||||||||||||
|
|
@@ -27,9 +25,9 @@ module Svc { | |||||||||||||||||||||||||||||
| @ Cancels a current operation | ||||||||||||||||||||||||||||||
| guarded input port cancelIn: Svc.CancelStatus | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| # Standard ports | ||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
| #Standard ports | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @ Port for requesting the current time | ||||||||||||||||||||||||||||||
| time get port timeCaller | ||||||||||||||||||||||||||||||
|
|
@@ -58,21 +56,21 @@ module Svc { | |||||||||||||||||||||||||||||
| @ Port to set the value of a parameter | ||||||||||||||||||||||||||||||
| param set port prmSetOut | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| # Commands | ||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
| #Commands | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| # Telemetry | ||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
| #Telemetry | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| # Parameters | ||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
| #Parameters | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| # Events | ||||||||||||||||||||||||||||||
| # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
| #Events | ||||||||||||||||||||||||||||||
| #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @ Notify we are not in IDLE state | ||||||||||||||||||||||||||||||
| event NotInIdle( | ||||||||||||||||||||||||||||||
|
|
@@ -220,6 +218,12 @@ module Svc { | |||||||||||||||||||||||||||||
| fileName: string size FileNameStringSize | ||||||||||||||||||||||||||||||
| ) severity warning low \ | ||||||||||||||||||||||||||||||
| format "Aborted after {} of {} bytes written to {}" | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @ Invalid input arguments received on a port handler | ||||||||||||||||||||||||||||||
| event InvalidInput( | ||||||||||||||||||||||||||||||
| handler: string size 16 | ||||||||||||||||||||||||||||||
| issue: string size 32 | ||||||||||||||||||||||||||||||
| ) severity warning high \ | ||||||||||||||||||||||||||||||
| format "Invalid input in {} handler: {}" | ||||||||||||||||||||||||||||||
|
Comment on lines
+222
to
+227
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 New The new
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 writeIn_handler reports FW_STATUS_DONE_WRITE even when writeBufferToFile fails
At
Svc/FileWorker/FileWorker.cpp:182,writeDoneOut_outalways reportsFW_STATUS_DONE_WRITEregardless of whetherwriteBufferToFilereturned false (indicating a write failure). This is pre-existing behavior unchanged by this PR, but it means callers cannot distinguish a successful write from a failed one via the done port status. The only indicator of failure is theWriteFileErrorevent emitted insidewriteToFile.(Refers to line 182)
Was this helpful? React with 👍 or 👎 to provide feedback.