Skip to content

Mark pure accessors const so FW_ASSERT sites pass CodeQL side-effect analysis#5392

Merged
thomas-bc merged 1 commit into
nasa:develfrom
JPL-Devin:devin/1783652041-assert-const-accessors
Jul 14, 2026
Merged

Mark pure accessors const so FW_ASSERT sites pass CodeQL side-effect analysis#5392
thomas-bc merged 1 commit into
nasa:develfrom
JPL-Devin:devin/1783652041-assert-const-accessors

Conversation

@lestarch-autobot

Copy link
Copy Markdown
Collaborator
Related Issue(s)
Has Unit Tests (y/n) n
Documentation Included (y/n) n
Generative AI was used in this contribution (y/n) AI

Change Description

Marks three logically-const accessors const (with mutable guard mutexes where the accessor locks):

  • Drv::IpSocket::isValidPort() (and the TcpClientSocket override)
  • Os::Task::getState() (m_lock becomes mutable)
  • Svc::FileDownlink::Mode::get() (m_mutex becomes mutable)

Rationale

CodeQL's JPL Rule 16 refinement (cpp/fprime/jpl-c/use-of-assertions-side-effect) treats calls to non-const member functions inside FW_ASSERT as potential side effects, since disabling the assertion could change program state. These accessors are pure - they only read state (taking a lock to do so is logical constness, the standard mutable mutex pattern) - so declaring them const both documents the contract and resolves 7 of the 46 hand-code alerts (IpSocket.cpp, UdpSocket.cpp, SocketComponentHelper.cpp, FileDownlink.cpp).

Testing/Review Recommendations

Full fprime-util build --all passes. The remaining flagged accessor patterns (const/non-const overload pairs such as SerializeBufferBase::getBuffAddr(), and errno reads) cannot be fixed with const and are addressed by a query refinement in a separate PR.

Future Work

Companion CodeQL query/config PR covering the overload-pair and errno false positives, the pack-2/pack-3 basic-int-types duplication, and the generated initializer_list loop-bounds pattern.

AI Usage (see policy)

Devin identified the flagged assertion sites via CodeQL analysis and authored the changes. IAMAI

Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report — base devel

Overall (line): 82.08% → 82.07% (-0.01)
Regression threshold: 0.50% (line).

Regressions

(none over threshold)

Modules changed

Module Line Δ Function Δ Branch Δ
Os/Generic 89.29 +0.13 88.16 +0.00 73.11 -0.24
Fw/DataStructures 98.48 +0.27 97.14 +0.00 83.21 +0.37
Os/Generic/Types 92.39 +0.36 92.86 +0.00 73.33 -0.96
Drv/TcpClient 80.00 +5.00 100.00 +0.00 63.16 +15.79

Modules without UTs

CFDP/Checksum/GTest, Drv/ByteStreamDriverModel, Drv/Interfaces, Drv/LinuxGpioDriver, Drv/LinuxI2cDriver, Drv/LinuxSpiDriver, Drv/LinuxUartDriver, Drv/Ports, Drv/Ports/DataTypes, FppTestProject/FppTest/interfaces, FppTestProject/FppTest/topology/async, FppTestProject/FppTest/topology/components/Comp, FppTestProject/FppTest/topology/components/Framework, FppTestProject/FppTest/topology/components/Receiver, FppTestProject/FppTest/topology/components/Sender, FppTestProject/FppTest/topology/guarded, FppTestProject/FppTest/topology/ports, FppTestProject/FppTest/topology/sync, FppTestProject/FppTest/topology/top_ports, FppTestProject/FppTest/topology/types, Fw/Cmd, Fw/Com, Fw/Comp, Fw/FilePacket/GTest, Fw/Fpy, Fw/Interfaces, Fw/Obj, Fw/Port, Fw/Ports/CompletionStatus, Fw/Ports/Ready, Fw/Ports/Signal, Fw/Ports/SuccessCondition, Fw/Prm, Fw/SerializableFile/test/TestSerializable, Fw/Sm, Fw/Test, Fw/Types/GTest, Os/Models, Svc/Cycle, Svc/DpPorts, Svc/Fatal, Svc/FatalHandler, Svc/FileDownlinkPorts, Svc/FprimeProtocol, Svc/Interfaces, Svc/PassiveConsoleTextLogger, Svc/Ping, Svc/PolyIf, Svc/Ports/CommsPorts, Svc/Ports/FilePorts, Svc/Ports/OsTimeEpoch, Svc/Ports/TlmPacketizerPorts, Svc/Ports/VersionPorts, Svc/Sched, Svc/Seq, Svc/Subtopologies/CdhCore, Svc/Subtopologies/ComCcsds, Svc/Subtopologies/ComFprime, Svc/Subtopologies/ComLoggerTee, Svc/Subtopologies/DataProducts, Svc/Subtopologies/DpCompression, Svc/Subtopologies/FileHandling, Svc/Types/TlmPacketizerTypes, Svc/WatchDog, TestDeploymentsProject/Ref/PingReceiver, TestDeploymentsProject/Ref/RecvBuffApp, TestDeploymentsProject/Ref/SendBuffApp, TestDeploymentsProject/Ref/Top, TestDeploymentsProject/Ref/TypeDemo, cmake/test/data/TestDeployment/TestBuildAutocoder, cmake/test/data/TestDeployment/TestChainedAutocoder, cmake/test/data/TestDeployment/TestHeaderAutocoder, cmake/test/data/TestDeployment/TestTargetAutocoder, cmake/test/data/test-fprime-library/TestLibrary/TestComponent, cmake/test/data/test-fprime-library2/TestLibrary2/TestComponent

@thomas-bc thomas-bc merged commit 12db00e into nasa:devel Jul 14, 2026
60 of 62 checks passed
@thomas-bc thomas-bc deleted the devin/1783652041-assert-const-accessors branch July 14, 2026 21:37
github-actions Bot added a commit that referenced this pull request Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants