fix(linklayer): set default value for variables to prevent unexpected behavior

Some variables had size mismatches with the data size defined in the frame segment. After deframing, this could leave residual bits as random and unknown values.
This commit is contained in:
Gatsby Van
2024-12-25 16:05:02 +08:00
parent 789e7fa30f
commit 2a8eb64e61
+13 -7
View File
@@ -478,7 +478,7 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
float nodePos; float nodePos;
L2_DEASSEMBLE(msg, L2_MSG_ADV_SRC_POSX, &nodePos); L2_DEASSEMBLE(msg, L2_MSG_ADV_SRC_POSX, &nodePos);
node->nodeInfo.pos.x = (double)nodePos; node->nodeInfo.pos.x = (double)nodePos;
L2_DEASSEMBLE(msg, L2_MSG_ADV_SRC_POSY, &nodePos); L2_DEASSEMBLE(msg, L2_MSG_ADV_SRC_POSY, &nodePos);
node->nodeInfo.pos.y = (double)nodePos; node->nodeInfo.pos.y = (double)nodePos;
L2_DEASSEMBLE(msg, L2_MSG_ADV_SRC_POSZ, &nodePos); L2_DEASSEMBLE(msg, L2_MSG_ADV_SRC_POSZ, &nodePos);
node->nodeInfo.pos.z = (double)nodePos; node->nodeInfo.pos.z = (double)nodePos;
@@ -487,7 +487,7 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
// Reset node ttl // Reset node ttl
node->ttlCnt = 0; node->ttlCnt = 0;
uint32_t netstartTime; uint32_t netstartTime = 0;
// Update net start time. // Update net start time.
L2_DEASSEMBLE(msg, L2_MSG_ADV_SRC_NETSTART_TIME, &netstartTime); L2_DEASSEMBLE(msg, L2_MSG_ADV_SRC_NETSTART_TIME, &netstartTime);
L2_EVENT netSetupDoneEvent = { L2_EVENT netSetupDoneEvent = {
@@ -496,10 +496,12 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
AssertL2Event(instPtr, &netSetupDoneEvent); AssertL2Event(instPtr, &netSetupDoneEvent);
// Calculate time deviation // Calculate time deviation
uint32_t frameNum, slotNum = 0; uint32_t frameNum = 0;
uint32_t slotNum = 0;
int64_t timeDev = 0;
L2_DEASSEMBLE(msg, L2_MSG_FRAME_NUM, &frameNum); L2_DEASSEMBLE(msg, L2_MSG_FRAME_NUM, &frameNum);
L2_DEASSEMBLE(msg, L2_MSG_SLOT_NUM, &slotNum); L2_DEASSEMBLE(msg, L2_MSG_SLOT_NUM, &slotNum);
Status = L2_GetTimeDeviation(instPtr, frameNum, slotNum, true, &(instPtr->log.timeDev)); Status = L2_GetTimeDeviation(instPtr, frameNum, slotNum, true, &timeDev);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
DBG_ERROR("Failed to compute time deviation.\n") DBG_ERROR("Failed to compute time deviation.\n")
@@ -507,7 +509,8 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
} }
// Time sync. // Time sync.
L2_TimeAdjust(instPtr, &(instPtr->log.timeDev)); L2_TimeAdjust(instPtr, &timeDev);
instPtr->log.timeDev = timeDev;
// trigger flag // trigger flag
AdvRecvStateUpdate(scanFsmPtr, true); AdvRecvStateUpdate(scanFsmPtr, true);
@@ -550,15 +553,18 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
node->ttlCnt = 0; node->ttlCnt = 0;
// Calculate time deviation // Calculate time deviation
uint32_t frameNum, slotNum = 0; uint32_t frameNum = 0;
uint32_t slotNum = 0;
int64_t timeDev = 0;
L2_DEASSEMBLE(msg, L2_MSG_FRAME_NUM, &frameNum); L2_DEASSEMBLE(msg, L2_MSG_FRAME_NUM, &frameNum);
L2_DEASSEMBLE(msg, L2_MSG_SLOT_NUM, &slotNum); L2_DEASSEMBLE(msg, L2_MSG_SLOT_NUM, &slotNum);
Status = L2_GetTimeDeviation(instPtr, frameNum, slotNum, true, &(instPtr->log.timeDev)); Status = L2_GetTimeDeviation(instPtr, frameNum, slotNum, true, &timeDev);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
DBG_ERROR("Failed to compute time deviation.\n") DBG_ERROR("Failed to compute time deviation.\n")
break; break;
} }
instPtr->log.timeDev = timeDev;
if (L2_GetNodeType(instPtr) != L2_NODE_HEAD) if (L2_GetNodeType(instPtr) != L2_NODE_HEAD)
{ {