Skip to content

Commit

Permalink
Merge pull request #26 from skliper/fix22-address_truncation
Browse files Browse the repository at this point in the history
Fix #22, Use %p for printing addresses, resolves truncation
  • Loading branch information
astrogeco authored Jun 1, 2022
2 parents 107c42c + c90a3d3 commit 3b474d3
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 118 deletions.
4 changes: 2 additions & 2 deletions fsw/src/mm_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ bool MM_LookupSymbolCmd(const CFE_SB_Buffer_t *BufPtr)
MM_AppData.HkPacket.Address = ResolvedAddr;

CFE_EVS_SendEvent(MM_SYM_LOOKUP_INF_EID, CFE_EVS_EventType_INFORMATION,
"Symbol Lookup Command: Name = '%s' Addr = 0x%08X", CmdPtr->SymName,
(unsigned int)ResolvedAddr);
"Symbol Lookup Command: Name = '%s' Addr = %p", CmdPtr->SymName,
(void *)ResolvedAddr);
Result = true;
}
else
Expand Down
8 changes: 4 additions & 4 deletions fsw/src/mm_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
{
CFE_EVS_SendEvent(
MM_DMP_MEM_FILE_INF_EID, CFE_EVS_EventType_INFORMATION,
"Dump Memory To File Command: Dumped %d bytes from address 0x%08X to file '%s'",
(int)MM_AppData.HkPacket.BytesProcessed, (unsigned int)SrcAddress, CmdPtr->FileName);
"Dump Memory To File Command: Dumped %d bytes from address %p to file '%s'",
(int)MM_AppData.HkPacket.BytesProcessed, (void *)SrcAddress, CmdPtr->FileName);
/*
** Update last action statistics
*/
Expand Down Expand Up @@ -540,9 +540,9 @@ bool MM_DumpInEventCmd(const CFE_SB_Buffer_t *BufPtr)

/*
** Append tail
** This adds up to 33 characters including the NUL terminator
** This adds up to 33 characters depending on pointer representation including the NUL terminator
*/
snprintf(TempString, MM_DUMPINEVENT_TEMP_CHARS, "from address: 0x%08lX", (unsigned long)SrcAddress);
snprintf(TempString, MM_DUMPINEVENT_TEMP_CHARS, "from address: %p", (void *)SrcAddress);
strncat(EventString, TempString, strlen(TempString));

/* Send it out */
Expand Down
46 changes: 23 additions & 23 deletions fsw/src/mm_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ bool MM_PokeMem(const MM_PokeCmd_t *CmdPtr, cpuaddr DestAddress)
MM_AppData.HkPacket.BytesProcessed = BytesProcessed;

CFE_EVS_SendEvent(EventID, CFE_EVS_EventType_INFORMATION,
"Poke Command: Addr = 0x%08X, Size = %d bits, Data = 0x%08X", (unsigned int)DestAddress,
DataSize, (unsigned int)DataValue);
"Poke Command: Addr = %p, Size = %d bits, Data = 0x%08X", (void *)DestAddress, DataSize,
(unsigned int)DataValue);
}
else
{
CFE_EVS_SendEvent(MM_PSP_WRITE_ERR_EID, CFE_EVS_EventType_ERROR,
"PSP write memory error: RC=0x%08X, Address=0x%08X, MemType=MEM%d", (unsigned int)PSP_Status,
(unsigned int)DestAddress, DataSize);
"PSP write memory error: RC=0x%08X, Address=%p, MemType=MEM%d", (unsigned int)PSP_Status,
(void *)DestAddress, DataSize);
}

return ValidPoke;
Expand Down Expand Up @@ -212,14 +212,14 @@ bool MM_PokeEeprom(const MM_PokeCmd_t *CmdPtr, cpuaddr DestAddress)
if (PSP_Status != CFE_PSP_SUCCESS)
{
CFE_EVS_SendEvent(MM_OS_EEPROMWRITE8_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_PSP_EepromWrite8 error received: RC = 0x%08X, Addr = 0x%08X",
(unsigned int)PSP_Status, (unsigned int)DestAddress);
"CFE_PSP_EepromWrite8 error received: RC = 0x%08X, Addr = %p",
(unsigned int)PSP_Status, (void *)DestAddress);
}
else
{
CFE_EVS_SendEvent(MM_POKE_BYTE_INF_EID, CFE_EVS_EventType_INFORMATION,
"Poke Command: Addr = 0x%08X, Size = 8 bits, Data = 0x%02X",
(unsigned int)DestAddress, ByteValue);
"Poke Command: Addr = %p, Size = 8 bits, Data = 0x%02X", (void *)DestAddress,
ByteValue);
ValidPoke = true;
}
break;
Expand All @@ -232,14 +232,14 @@ bool MM_PokeEeprom(const MM_PokeCmd_t *CmdPtr, cpuaddr DestAddress)
if (PSP_Status != CFE_PSP_SUCCESS)
{
CFE_EVS_SendEvent(MM_OS_EEPROMWRITE16_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_PSP_EepromWrite16 error received: RC = 0x%08X, Addr = 0x%08X",
(unsigned int)PSP_Status, (unsigned int)DestAddress);
"CFE_PSP_EepromWrite16 error received: RC = 0x%08X, Addr = %p",
(unsigned int)PSP_Status, (void *)DestAddress);
}
else
{
CFE_EVS_SendEvent(MM_POKE_WORD_INF_EID, CFE_EVS_EventType_INFORMATION,
"Poke Command: Addr = 0x%08X, Size = 16 bits, Data = 0x%04X",
(unsigned int)DestAddress, WordValue);
"Poke Command: Addr = %p, Size = 16 bits, Data = 0x%04X", (void *)DestAddress,
WordValue);
ValidPoke = true;
}
break;
Expand All @@ -251,14 +251,14 @@ bool MM_PokeEeprom(const MM_PokeCmd_t *CmdPtr, cpuaddr DestAddress)
if (PSP_Status != CFE_PSP_SUCCESS)
{
CFE_EVS_SendEvent(MM_OS_EEPROMWRITE32_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_PSP_EepromWrite32 error received: RC = 0x%08X, Addr = 0x%08X",
(unsigned int)PSP_Status, (unsigned int)DestAddress);
"CFE_PSP_EepromWrite32 error received: RC = 0x%08X, Addr = %p",
(unsigned int)PSP_Status, (void *)DestAddress);
}
else
{
CFE_EVS_SendEvent(MM_POKE_DWORD_INF_EID, CFE_EVS_EventType_INFORMATION,
"Poke Command: Addr = 0x%08X, Size = 32 bits, Data = 0x%08X",
(unsigned int)DestAddress, (unsigned int)(CmdPtr->Data));
"Poke Command: Addr = %p, Size = 32 bits, Data = 0x%08X", (void *)DestAddress,
(unsigned int)(CmdPtr->Data));
ValidPoke = true;
}
break;
Expand Down Expand Up @@ -328,8 +328,8 @@ bool MM_LoadMemWIDCmd(const CFE_SB_Buffer_t *BufPtr)

CmdResult = true;
CFE_EVS_SendEvent(MM_LOAD_WID_INF_EID, CFE_EVS_EventType_INFORMATION,
"Load Memory WID Command: Wrote %d bytes to address: 0x%08X",
(int)CmdPtr->NumOfBytes, (unsigned int)DestAddress);
"Load Memory WID Command: Wrote %d bytes to address: %p", (int)CmdPtr->NumOfBytes,
(void *)DestAddress);

/* Update last action statistics */
MM_AppData.HkPacket.LastAction = MM_LOAD_WID;
Expand Down Expand Up @@ -471,9 +471,9 @@ bool MM_LoadMemFromFileCmd(const CFE_SB_Buffer_t *BufPtr)
{
CFE_EVS_SendEvent(MM_LD_MEM_FILE_INF_EID, CFE_EVS_EventType_INFORMATION,
"Load Memory From File Command: Loaded %d bytes to "
"address 0x%08X from file '%s'",
(int)MM_AppData.HkPacket.BytesProcessed,
(unsigned int)DestAddress, CmdPtr->FileName);
"address %p from file '%s'",
(int)MM_AppData.HkPacket.BytesProcessed, (void *)DestAddress,
CmdPtr->FileName);
}

} /* end MM_VerifyFileLoadParams if */
Expand Down Expand Up @@ -782,8 +782,8 @@ bool MM_FillMemCmd(const CFE_SB_Buffer_t *BufPtr)
if (MM_AppData.HkPacket.LastAction == MM_FILL)
{
CFE_EVS_SendEvent(MM_FILL_INF_EID, CFE_EVS_EventType_INFORMATION,
"Fill Memory Command: Filled %d bytes at address: 0x%08X with pattern: 0x%08X",
(int)MM_AppData.HkPacket.BytesProcessed, (unsigned int)DestAddress,
"Fill Memory Command: Filled %d bytes at address: %p with pattern: 0x%08X",
(int)MM_AppData.HkPacket.BytesProcessed, (void *)DestAddress,
(unsigned int)MM_AppData.HkPacket.DataValue);
}
}
Expand Down
39 changes: 19 additions & 20 deletions fsw/src/mm_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool MM_VerifyPeekPokeParams(cpuaddr Address, uint8 MemType, uint8 SizeInBits)
{
Valid = false;
CFE_EVS_SendEvent(MM_ALIGN16_ERR_EID, CFE_EVS_EventType_ERROR,
"Data and address not 16 bit aligned: Addr = 0x%08X Size = %d", (unsigned int)Address,
"Data and address not 16 bit aligned: Addr = %p Size = %d", (void *)Address,
SizeInBytes);
}
break;
Expand All @@ -172,7 +172,7 @@ bool MM_VerifyPeekPokeParams(cpuaddr Address, uint8 MemType, uint8 SizeInBits)
{
Valid = false;
CFE_EVS_SendEvent(MM_ALIGN32_ERR_EID, CFE_EVS_EventType_ERROR,
"Data and address not 32 bit aligned: Addr = 0x%08X Size = %d", (unsigned int)Address,
"Data and address not 32 bit aligned: Addr = %p Size = %d", (void *)Address,
SizeInBytes);
}
break;
Expand All @@ -196,9 +196,9 @@ bool MM_VerifyPeekPokeParams(cpuaddr Address, uint8 MemType, uint8 SizeInBits)
{
Valid = false;
CFE_EVS_SendEvent(MM_OS_MEMVALIDATE_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = 0x%08X Size = %d "
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = %p Size = %d "
"MemType = MEM_RAM",
(unsigned int)OS_Status, (unsigned int)Address, SizeInBytes);
(unsigned int)OS_Status, (void *)Address, SizeInBytes);
}
break;

Expand All @@ -209,9 +209,9 @@ bool MM_VerifyPeekPokeParams(cpuaddr Address, uint8 MemType, uint8 SizeInBits)
{
Valid = false;
CFE_EVS_SendEvent(MM_OS_MEMVALIDATE_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = 0x%08X Size = %d "
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = %p Size = %d "
"MemType = MEM_EEPROM",
(unsigned int)OS_Status, (unsigned int)Address, SizeInBytes);
(unsigned int)OS_Status, (void *)Address, SizeInBytes);
}
break;

Expand All @@ -224,8 +224,8 @@ bool MM_VerifyPeekPokeParams(cpuaddr Address, uint8 MemType, uint8 SizeInBits)
Valid = false;
CFE_EVS_SendEvent(
MM_OS_MEMVALIDATE_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = 0x%08X Size = %d MemType = MEM32",
(unsigned int)OS_Status, (unsigned int)Address, SizeInBytes);
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = %p Size = %d MemType = MEM32",
(unsigned int)OS_Status, (void *)Address, SizeInBytes);
}
/*
** Peeks and Pokes must be 32 bits wide for this memory type
Expand All @@ -248,8 +248,8 @@ bool MM_VerifyPeekPokeParams(cpuaddr Address, uint8 MemType, uint8 SizeInBits)
Valid = false;
CFE_EVS_SendEvent(
MM_OS_MEMVALIDATE_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = 0x%08X Size = %d MemType = MEM16",
(unsigned int)OS_Status, (unsigned int)Address, SizeInBytes);
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = %p Size = %d MemType = MEM16",
(unsigned int)OS_Status, (void *)Address, SizeInBytes);
}
/*
** Peeks and Pokes must be 16 bits wide for this memory type
Expand All @@ -272,8 +272,8 @@ bool MM_VerifyPeekPokeParams(cpuaddr Address, uint8 MemType, uint8 SizeInBits)
Valid = false;
CFE_EVS_SendEvent(
MM_OS_MEMVALIDATE_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = 0x%08X Size = %d MemType = MEM8",
(unsigned int)OS_Status, (unsigned int)Address, SizeInBytes);
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = %p Size = %d MemType = MEM8",
(unsigned int)OS_Status, (void *)Address, SizeInBytes);
}
/*
** Peeks and Pokes must be 8 bits wide for this memory type
Expand Down Expand Up @@ -396,8 +396,8 @@ bool MM_VerifyLoadDumpParams(cpuaddr Address, uint8 MemType, uint32 SizeInBytes,
{
Valid = false;
CFE_EVS_SendEvent(MM_ALIGN32_ERR_EID, CFE_EVS_EventType_ERROR,
"Data and address not 32 bit aligned: Addr = 0x%08X Size = %d",
(unsigned int)Address, (int)SizeInBytes);
"Data and address not 32 bit aligned: Addr = %p Size = %d", (void *)Address,
(int)SizeInBytes);
}
break;
#endif
Expand All @@ -421,8 +421,8 @@ bool MM_VerifyLoadDumpParams(cpuaddr Address, uint8 MemType, uint32 SizeInBytes,
{
Valid = false;
CFE_EVS_SendEvent(MM_ALIGN16_ERR_EID, CFE_EVS_EventType_ERROR,
"Data and address not 16 bit aligned: Addr = 0x%08X Size = %d",
(unsigned int)Address, (int)SizeInBytes);
"Data and address not 16 bit aligned: Addr = %p Size = %d", (void *)Address,
(int)SizeInBytes);
}
break;
#endif
Expand Down Expand Up @@ -470,10 +470,9 @@ bool MM_VerifyLoadDumpParams(cpuaddr Address, uint8 MemType, uint32 SizeInBytes,
if (PSP_Status != CFE_PSP_SUCCESS)
{
Valid = false;
CFE_EVS_SendEvent(
MM_OS_MEMVALIDATE_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = 0x%08X Size = %d MemType = %s",
(unsigned int)PSP_Status, (unsigned int)Address, (int)SizeInBytes, MemTypeStr);
CFE_EVS_SendEvent(MM_OS_MEMVALIDATE_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_PSP_MemValidateRange error received: RC = 0x%08X Addr = %p Size = %d MemType = %s",
(unsigned int)PSP_Status, (void *)Address, (int)SizeInBytes, MemTypeStr);
}
}

Expand Down
3 changes: 1 addition & 2 deletions unit-test/mm_app_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1271,8 +1271,7 @@ void MM_LookupSymbolCmd_Test_Nominal(void)
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Symbol Lookup Command: Name = '%%s' Addr = 0x%%08X");
snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "Symbol Lookup Command: Name = '%%s' Addr = %%p");

UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false);
Expand Down
12 changes: 6 additions & 6 deletions unit-test/mm_dump_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ void MM_DumpMemToFileCmd_Test_RAM(void)
bool Result;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Dump Memory To File Command: Dumped %%d bytes from address 0x%%08X to file '%%s'");
"Dump Memory To File Command: Dumped %%d bytes from address %%p to file '%%s'");

TestMsgId = CFE_SB_ValueToMsgId(MM_CMD_MID);
FcnCode = MM_DUMP_MEM_TO_FILE_CC;
Expand Down Expand Up @@ -655,7 +655,7 @@ void MM_DumpMemToFileCmd_Test_EEPROM(void)
bool Result;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Dump Memory To File Command: Dumped %%d bytes from address 0x%%08X to file '%%s'");
"Dump Memory To File Command: Dumped %%d bytes from address %%p to file '%%s'");

TestMsgId = CFE_SB_ValueToMsgId(MM_CMD_MID);
FcnCode = MM_DUMP_MEM_TO_FILE_CC;
Expand Down Expand Up @@ -730,7 +730,7 @@ void MM_DumpMemToFileCmd_Test_MEM32(void)
bool Result;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Dump Memory To File Command: Dumped %%d bytes from address 0x%%08X to file '%%s'");
"Dump Memory To File Command: Dumped %%d bytes from address %%p to file '%%s'");

TestMsgId = CFE_SB_ValueToMsgId(MM_CMD_MID);
FcnCode = MM_DUMP_MEM_TO_FILE_CC;
Expand Down Expand Up @@ -804,7 +804,7 @@ void MM_DumpMemToFileCmd_Test_MEM16(void)
bool Result;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Dump Memory To File Command: Dumped %%d bytes from address 0x%%08X to file '%%s'");
"Dump Memory To File Command: Dumped %%d bytes from address %%p to file '%%s'");

TestMsgId = CFE_SB_ValueToMsgId(MM_CMD_MID);
FcnCode = MM_DUMP_MEM_TO_FILE_CC;
Expand Down Expand Up @@ -878,7 +878,7 @@ void MM_DumpMemToFileCmd_Test_MEM8(void)
bool Result;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Dump Memory To File Command: Dumped %%d bytes from address 0x%%08X to file '%%s'");
"Dump Memory To File Command: Dumped %%d bytes from address %%p to file '%%s'");

TestMsgId = CFE_SB_ValueToMsgId(MM_CMD_MID);
FcnCode = MM_DUMP_MEM_TO_FILE_CC;
Expand Down Expand Up @@ -1019,7 +1019,7 @@ void MM_DumpMemToFileCmd_Test_CloseError(void)
bool Result;

snprintf(ExpectedEventString[0], CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Dump Memory To File Command: Dumped %%d bytes from address 0x%%08X to file '%%s'");
"Dump Memory To File Command: Dumped %%d bytes from address %%p to file '%%s'");

snprintf(ExpectedEventString[1], CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"OS_close error received: RC = 0x%%08X File = '%%s'");
Expand Down
Loading

0 comments on commit 3b474d3

Please sign in to comment.