Conversation
There was a problem hiding this comment.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
| case Fpy::DirectiveId::CMD: { | ||
| new (&deserializedDirective.cmd) FpySequencer_CmdDirective(); | ||
| // same deserialization behavior as SET_LVAR | ||
|
|
||
| // first deserialize the opcode | ||
| FwOpcodeType opcode; | ||
| status = argBuf.deserialize(opcode); | ||
| if (status != Fw::SerializeStatus::FW_SERIALIZE_OK) { | ||
| this->log_WARNING_HI_DirectiveDeserializeError(stmt.getopCode(), this->m_runtime.nextStatementIndex - 1, | ||
| status, argBuf.getBuffLeft(), argBuf.getBuffLength()); | ||
| return Fw::Success::FAILURE; | ||
| } | ||
|
|
||
| deserializedDirective.cmd.setopCode(opcode); | ||
| // how many bytes are left? | ||
| FwSizeType cmdArgBufSize = argBuf.getBuffLeft(); | ||
|
|
||
| // check to make sure the value will fit in the FpySequencer_CmdDirective::argBuf | ||
| if (cmdArgBufSize > Fpy::MAX_LOCAL_VARIABLE_BUFFER_SIZE) { | ||
| this->log_WARNING_HI_DirectiveDeserializeError(stmt.getopCode(), this->m_runtime.nextStatementIndex - 1, | ||
| Fw::SerializeStatus::FW_DESERIALIZE_FORMAT_ERROR, | ||
| argBuf.getBuffLeft(), argBuf.getBuffLength()); | ||
| return Fw::Success::FAILURE; | ||
| } | ||
|
|
||
| // okay, it will fit. put it in | ||
| status = argBuf.deserialize(deserializedDirective.cmd.getargBuf(), cmdArgBufSize, true); | ||
|
|
||
| if (status != Fw::SerializeStatus::FW_SERIALIZE_OK) { | ||
| this->log_WARNING_HI_DirectiveDeserializeError(stmt.getopCode(), this->m_runtime.nextStatementIndex - 1, | ||
| status, argBuf.getBuffLeft(), argBuf.getBuffLength()); | ||
| return Fw::Success::FAILURE; | ||
| } | ||
|
|
||
| // now there should be nothing left, otherwise coding err | ||
| FW_ASSERT(argBuf.getBuffLeft() == 0, static_cast<FwAssertArgType>(argBuf.getBuffLeft())); | ||
|
|
||
| // and set the buf size now that we know it | ||
| deserializedDirective.cmd.set_argBufSize(cmdArgBufSize); | ||
| break; | ||
| } | ||
| // fallthrough on purpose | ||
| case Fpy::DirectiveId::DESER_LVAR_8: | ||
| case Fpy::DirectiveId::DESER_LVAR_4: | ||
| case Fpy::DirectiveId::DESER_LVAR_2: | ||
| case Fpy::DirectiveId::DESER_LVAR_1: { | ||
| new (&deserializedDirective.deserLocalVar) FpySequencer_DeserLocalVarDirective(); | ||
|
|
||
| U8 deserSize; | ||
|
|
||
| if (stmt.getopCode() == Fpy::DirectiveId::DESER_LVAR_1) { | ||
| deserSize = 1; | ||
| } else if (stmt.getopCode() == Fpy::DirectiveId::DESER_LVAR_2) { | ||
| deserSize = 2; | ||
| } else if (stmt.getopCode() == Fpy::DirectiveId::DESER_LVAR_4) { | ||
| deserSize = 4; | ||
| } else if (stmt.getopCode() == Fpy::DirectiveId::DESER_LVAR_8) { | ||
| deserSize = 8; | ||
| } else { | ||
| FW_ASSERT(0, static_cast<FwAssertArgType>(stmt.getopCode())); | ||
| return Fw::Success::FAILURE; | ||
| } | ||
|
|
||
| deserializedDirective.deserLocalVar.set_deserSize(deserSize); | ||
|
|
||
| U8 srcLvarIdx; | ||
| status = argBuf.deserialize(srcLvarIdx); | ||
| if (status != Fw::SerializeStatus::FW_SERIALIZE_OK) { | ||
| this->log_WARNING_HI_DirectiveDeserializeError(stmt.getopCode(), this->m_runtime.nextStatementIndex - 1, | ||
| status, argBuf.getBuffLeft(), argBuf.getBuffLength()); | ||
| return Fw::Success::FAILURE; | ||
| } | ||
| deserializedDirective.deserLocalVar.setsrcLvarIdx(srcLvarIdx); | ||
|
|
||
| FwSizeType srcOffset; | ||
| status = argBuf.deserialize(srcOffset); | ||
| if (status != Fw::SerializeStatus::FW_SERIALIZE_OK) { | ||
| this->log_WARNING_HI_DirectiveDeserializeError(stmt.getopCode(), this->m_runtime.nextStatementIndex - 1, | ||
| status, argBuf.getBuffLeft(), argBuf.getBuffLength()); | ||
| return Fw::Success::FAILURE; | ||
| } | ||
| deserializedDirective.deserLocalVar.setsrcOffset(srcOffset); | ||
|
|
||
| U8 destReg; | ||
| status = argBuf.deserialize(destReg); | ||
| if (status != Fw::SerializeStatus::FW_SERIALIZE_OK || argBuf.getBuffLeft() != 0) { | ||
| this->log_WARNING_HI_DirectiveDeserializeError(stmt.getopCode(), this->m_runtime.nextStatementIndex - 1, | ||
| status, argBuf.getBuffLeft(), argBuf.getBuffLength()); | ||
| return Fw::Success::FAILURE; | ||
| } | ||
| deserializedDirective.deserLocalVar.setdestReg(destReg); | ||
| break; | ||
| } | ||
| case Fpy::DirectiveId::SET_REG: { | ||
| new (&deserializedDirective.setReg) FpySequencer_SetRegDirective(); | ||
| status = argBuf.deserialize(deserializedDirective.setReg); | ||
| if (status != Fw::SerializeStatus::FW_SERIALIZE_OK || argBuf.getBuffLeft() != 0) { | ||
| this->log_WARNING_HI_DirectiveDeserializeError(stmt.getopCode(), this->m_runtime.nextStatementIndex - 1, | ||
| status, argBuf.getBuffLeft(), argBuf.getBuffLength()); | ||
| return Fw::Success::FAILURE; | ||
| } | ||
| break; | ||
| } | ||
| // fallthrough on purpose | ||
| case Fpy::DirectiveId::OR: | ||
| case Fpy::DirectiveId::AND: | ||
| case Fpy::DirectiveId::EQ: | ||
| case Fpy::DirectiveId::NE: | ||
| case Fpy::DirectiveId::UGT: | ||
| case Fpy::DirectiveId::ULT: | ||
| case Fpy::DirectiveId::ULE: | ||
| case Fpy::DirectiveId::UGE: |
Check notice
Code scanning / CodeQL
Long switch case Note
There was a problem hiding this comment.
This is legitimate. We should track this as a fix for the future.
| || directive.getres() >= Fpy::NUM_REGISTERS) { | ||
| error = DirectiveError::REGISTER_OUT_OF_BOUNDS; | ||
| return Signal::stmtResponse_failure; | ||
| } |
Check notice
Code scanning / CodeQL
Long function without assertion Note
| || directive.getres() >= Fpy::NUM_REGISTERS) { | ||
| error = DirectiveError::REGISTER_OUT_OF_BOUNDS; | ||
| return Signal::stmtResponse_failure; | ||
| } |
Check notice
Code scanning / CodeQL
Function too long Note
| Signal FpySequencer::not_directiveHandler(const FpySequencer_NotDirective& directive, DirectiveError& error) { | ||
| if (directive.getsrc() >= Fpy::NUM_REGISTERS | ||
| || directive.getres() >= Fpy::NUM_REGISTERS) { | ||
| error = DirectiveError::REGISTER_OUT_OF_BOUNDS; |
Check notice
Code scanning / CodeQL
Long function without assertion Note
| Signal FpySequencer::setLocalVar_directiveHandler(const FpySequencer_SetLocalVarDirective& directive) { | ||
| if (directive.getindex() >= Fpy::MAX_SEQUENCE_LOCAL_VARIABLES) { | ||
| //! Internal interface handler for directive_setSerReg | ||
| Signal FpySequencer::setSerReg_directiveHandler(const FpySequencer_SetSerRegDirective& directive, DirectiveError& error) { |
Check notice
Code scanning / CodeQL
Long function without assertion Note
| lvar.valueSize = prmValue.getBuffLength(); | ||
| // copy value into serReg | ||
| Runtime::SerializableReg& serReg = this->m_runtime.serRegs[directive.getdestSerRegIndex()]; | ||
| memcpy(serReg.value, prmValue.getBuffAddr(), static_cast<size_t>(prmValue.getBuffLength())); |
Check notice
Code scanning / CodeQL
Long function without assertion Note
|
|
||
| Signal FpySequencer::deserSerReg_directiveHandler(const FpySequencer_DeserSerRegDirective& directive, DirectiveError& error) { | ||
| if (directive.getsrcSerRegIdx() >= Fpy::NUM_SERIALIZABLE_REGISTERS) { | ||
| error = DirectiveError::SER_REG_OUT_OF_BOUNDS; |
Check notice
Code scanning / CodeQL
Long function without assertion Note
Svc/FpySequencer/FpySequencer.hpp
Outdated
| // values of unspecified type | ||
| I64 registers[Fpy::NUM_REGISTERS] = {0}; | ||
|
|
||
| // local var -> local array, scratch array |
| } | ||
|
|
||
| if (conditional) { | ||
| if (reg(directive.getconditionalReg())) { |
There was a problem hiding this comment.
if dir uses registers now
| return Signal::stmtResponse_failure; | ||
| } | ||
|
|
||
| // TODO can I use htons/htonl? this code could be way simpler |
There was a problem hiding this comment.
i'd like to do this. are we allowed to use htons/htonl? or is that a linux/posix thing and we don't want to restrict?
| ::testing::InitGoogleTest(&argc, argv); | ||
| return RUN_ALL_TESTS(); | ||
| } No newline at end of file | ||
| // int main(int argc, char** argv) { |
There was a problem hiding this comment.
this function wasn't necessary, you can remove it from all fprime components i believe
|
Todo remove all references to the word "statement", replace with "directive" |
|
@LeStarch this is ready for review |
|
@zimri-leisher is this ready for review? |
yep! |
| } | ||
|
|
||
| } // namespace Svc | ||
|
|
There was a problem hiding this comment.
I am pretty sure this is necessary....no?
There was a problem hiding this comment.
no don't believe so, gtest adds it automatically i think
| struct CmdDirective { | ||
| opCode: FwOpcodeType | ||
| @ the arg buf of the cmd | ||
| # TODO please don't let me merge this. need to find a better const here |
There was a problem hiding this comment.
This statement is specifically telling me to block the merge.
There was a problem hiding this comment.
ah yes because I wanted to discuss... how big should the size of the cmd arg buf be in Fpy? I can't reference the FPrime CMD_ARG_BUF_MAX_SIZE because it's a #define constant. For now I'm using the size of the serializable registers
Change Description
DirectiveErrorcodes, which let you diagnose the specific reason why a sequence failed at a bytecode level. Useful for debugging the sequencer