Mark pure accessors const so FW_ASSERT sites pass CodeQL side-effect analysis#5392
Conversation
Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
Coverage report — base
|
| 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
…ide-effect analysis (#5392)
Change Description
Marks three logically-const accessors
const(withmutableguard mutexes where the accessor locks):Drv::IpSocket::isValidPort()(and theTcpClientSocketoverride)Os::Task::getState()(m_lockbecomesmutable)Svc::FileDownlink::Mode::get()(m_mutexbecomesmutable)Rationale
CodeQL's JPL Rule 16 refinement (
cpp/fprime/jpl-c/use-of-assertions-side-effect) treats calls to non-const member functions insideFW_ASSERTas 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 standardmutablemutex pattern) - so declaring themconstboth 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 --allpasses. The remaining flagged accessor patterns (const/non-const overload pairs such asSerializeBufferBase::getBuffAddr(), anderrnoreads) cannot be fixed withconstand 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