Skip to content

Commit

Permalink
Fix #67, Use size_t for 'size' variables
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkslprpt committed May 25, 2023
1 parent d89f08c commit 2c0f6e1
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 312 deletions.
8 changes: 3 additions & 5 deletions fsw/inc/mm_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command header */

uint8 DataSize; /**< \brief Size of the data to be read */
uint8 Padding[3]; /**< \brief Structure padding */
size_t DataSize; /**< \brief Size of the data to be read */
MM_MemType_t MemType; /**< \brief Memory type to peek data from */
MM_SymAddr_t SrcSymAddress; /**< \brief Symbolic source peek address */
} MM_PeekCmd_t;
Expand All @@ -102,8 +101,7 @@ typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command header */

uint8 DataSize; /**< \brief Size of the data to be written */
uint8 Padding1[3]; /**< \brief Structure padding */
size_t DataSize; /**< \brief Size of the data to be written */
MM_MemType_t MemType; /**< \brief Memory type to poke data to */
uint32 Data; /**< \brief Data to be written */
uint8 Padding2[4]; /**< \brief Structure padding */
Expand Down Expand Up @@ -253,7 +251,7 @@ typedef struct
MM_MemType_t MemType; /**< \brief Memory type for last command */
cpuaddr Address; /**< \brief Fully resolved address used for last command */
uint32 DataValue; /**< \brief Last command data (fill pattern or peek/poke value) */
uint32 BytesProcessed; /**< \brief Bytes processed for last command */
size_t BytesProcessed; /**< \brief Bytes processed for last command */
char FileName[OS_MAX_PATH_LEN]; /**< \brief Name of the data file used for last command, where applicable */
} MM_HkPacket_t;

Expand Down
30 changes: 15 additions & 15 deletions fsw/src/mm_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool MM_PeekCmd(const CFE_SB_Buffer_t *BufPtr)
bool Valid;
const MM_PeekCmd_t *CmdPtr;
cpuaddr SrcAddress = 0;
uint16 ExpectedLength = sizeof(MM_PeekCmd_t);
size_t ExpectedLength = sizeof(MM_PeekCmd_t);
bool Result = false;
MM_SymAddr_t SrcSymAddress;

Expand Down Expand Up @@ -103,9 +103,9 @@ bool MM_PeekMem(const MM_PeekCmd_t *CmdPtr, cpuaddr SrcAddress)
uint16 WordValue = 0;
uint32 DWordValue = 0;
int32 PSP_Status = 0;
uint32 BytesProcessed = 0;
size_t BytesProcessed = 0;
uint32 DataValue = 0;
uint8 DataSize = 0;
size_t DataSize = 0;
uint32 EventID = 0;

/*
Expand Down Expand Up @@ -169,14 +169,14 @@ bool MM_PeekMem(const MM_PeekCmd_t *CmdPtr, cpuaddr SrcAddress)
MM_AppData.HkPacket.DataValue = DataValue;

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

return ValidPeek;
Expand All @@ -198,7 +198,7 @@ bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
const MM_DumpMemToFileCmd_t *CmdPtr;
CFE_FS_Header_t CFEFileHeader;
MM_LoadDumpFileHeader_t MMFileHeader;
uint16 ExpectedLength = sizeof(MM_DumpMemToFileCmd_t);
size_t ExpectedLength = sizeof(MM_DumpMemToFileCmd_t);

/* Verify command packet length */
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
Expand Down Expand Up @@ -376,8 +376,8 @@ bool MM_DumpMemToFile(osal_id_t FileHandle, const char *FileName, const MM_LoadD
bool ValidDump = false;
int32 OS_Status;
uint32 BytesRemaining = FileHeader->NumOfBytes;
uint32 BytesProcessed = 0;
uint32 SegmentSize = MM_MAX_DUMP_DATA_SEG;
size_t BytesProcessed = 0;
size_t SegmentSize = MM_MAX_DUMP_DATA_SEG;
uint8 *SourcePtr = (uint8 *)(FileHeader->SymAddress.Offset);
uint8 *ioBuffer = (uint8 *)&MM_AppData.DumpBuffer[0];

Expand Down Expand Up @@ -407,8 +407,8 @@ bool MM_DumpMemToFile(osal_id_t FileHandle, const char *FileName, const MM_LoadD
{
BytesRemaining = 0;
CFE_EVS_SendEvent(MM_OS_WRITE_EXP_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_write error received: RC = %d, Expected = %d, File = '%s'", OS_Status,
(int)SegmentSize, FileName);
"OS_write error received: RC = %d, Expected = %u, File = '%s'", OS_Status,
(unsigned int)SegmentSize, FileName);
}
}

Expand Down Expand Up @@ -461,8 +461,8 @@ bool MM_WriteFileHeaders(const char *FileName, osal_id_t FileHandle, CFE_FS_Head
/* We either got an error or didn't read as much data as expected */
Valid = false;
CFE_EVS_SendEvent(MM_OS_WRITE_EXP_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_write error received: RC = %d Expected = %d File = '%s'", OS_Status,
(int)sizeof(MM_LoadDumpFileHeader_t), FileName);
"OS_write error received: RC = %d Expected = %u File = '%s'", OS_Status,
(unsigned int)sizeof(MM_LoadDumpFileHeader_t), FileName);

} /* end OS_write if */

Expand All @@ -483,7 +483,7 @@ bool MM_DumpInEventCmd(const CFE_SB_Buffer_t *BufPtr)
uint32 i;
int32 EventStringTotalLength = 0;
cpuaddr SrcAddress = 0;
uint16 ExpectedLength = sizeof(MM_DumpInEventCmd_t);
size_t ExpectedLength = sizeof(MM_DumpInEventCmd_t);
uint8 * BytePtr;
char TempString[MM_DUMPINEVENT_TEMP_CHARS];
const char HeaderString[] = "Memory Dump: ";
Expand Down
38 changes: 19 additions & 19 deletions fsw/src/mm_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool MM_PokeCmd(const CFE_SB_Buffer_t *BufPtr)
bool Valid = false;
cpuaddr DestAddress = 0;
const MM_PokeCmd_t *CmdPtr;
uint16 ExpectedLength = sizeof(MM_PokeCmd_t);
size_t ExpectedLength = sizeof(MM_PokeCmd_t);
MM_SymAddr_t DestSymAddress;

/* Verify command packet length */
Expand Down Expand Up @@ -112,9 +112,9 @@ bool MM_PokeMem(const MM_PokeCmd_t *CmdPtr, cpuaddr DestAddress)
uint16 WordValue;
CFE_Status_t PSP_Status = CFE_PSP_SUCCESS;
uint32 DataValue = 0;
uint32 BytesProcessed = 0;
size_t BytesProcessed = 0;
bool ValidPoke = false;
uint8 DataSize = 0; /* only used for giving MEM type/size in events */
size_t DataSize = 0; /* only used for giving MEM type/size in events */
uint32 EventID = 0;

/* Write input number of bits to destination address */
Expand Down Expand Up @@ -173,14 +173,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 = %p, Size = %d bits, Data = 0x%08X", (void *)DestAddress, DataSize,
(unsigned int)DataValue);
"Poke Command: Addr = %p, Size = %u bits, Data = 0x%08X", (void *)DestAddress,
(unsigned int)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=%p, MemType=MEM%d", (unsigned int)PSP_Status,
(void *)DestAddress, DataSize);
"PSP write memory error: RC=0x%08X, Address=%p, MemType=MEM%u", (unsigned int)PSP_Status,
(void *)DestAddress, (unsigned int)DataSize);
}

return ValidPoke;
Expand All @@ -197,7 +197,7 @@ bool MM_PokeEeprom(const MM_PokeCmd_t *CmdPtr, cpuaddr DestAddress)
uint16 WordValue;
CFE_Status_t PSP_Status;
uint32 DataValue = 0;
uint32 BytesProcessed = 0;
size_t BytesProcessed = 0;
bool ValidPoke = false;

CFE_ES_PerfLogEntry(MM_EEPROM_POKE_PERF_ID);
Expand Down Expand Up @@ -298,7 +298,7 @@ bool MM_LoadMemWIDCmd(const CFE_SB_Buffer_t *BufPtr)
const MM_LoadMemWIDCmd_t *CmdPtr;
uint32 ComputedCRC;
cpuaddr DestAddress = 0;
uint16 ExpectedLength = sizeof(MM_LoadMemWIDCmd_t);
size_t ExpectedLength = sizeof(MM_LoadMemWIDCmd_t);
bool CmdResult = false;
MM_SymAddr_t DestSymAddress;

Expand Down Expand Up @@ -376,7 +376,7 @@ bool MM_LoadMemFromFileCmd(const CFE_SB_Buffer_t *BufPtr)
CFE_FS_Header_t CFEFileHeader;
MM_LoadDumpFileHeader_t MMFileHeader;
uint32 ComputedCRC;
uint16 ExpectedLength = sizeof(MM_LoadMemFromFileCmd_t);
size_t ExpectedLength = sizeof(MM_LoadMemFromFileCmd_t);

memset(&MMFileHeader, 0, sizeof(MMFileHeader));

Expand Down Expand Up @@ -560,9 +560,9 @@ bool MM_LoadMemFromFile(osal_id_t FileHandle, const char *FileName, const MM_Loa
{
bool Valid = false;
int32 BytesRemaining = FileHeader->NumOfBytes;
int32 BytesProcessed = 0;
size_t BytesProcessed = 0;
int32 ReadLength;
uint32 SegmentSize = MM_MAX_LOAD_DATA_SEG;
size_t SegmentSize = MM_MAX_LOAD_DATA_SEG;
uint8 *ioBuffer = (uint8 *)&MM_AppData.LoadBuffer[0];
uint8 *TargetPointer = (uint8 *)DestAddress;

Expand Down Expand Up @@ -595,8 +595,8 @@ bool MM_LoadMemFromFile(osal_id_t FileHandle, const char *FileName, const MM_Loa
else
{
CFE_EVS_SendEvent(MM_OS_READ_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_read error received: RC = 0x%08X Expected = %d File = '%s'", (unsigned int)ReadLength,
(int)SegmentSize, FileName);
"OS_read error received: RC = 0x%08X Expected = %u File = '%s'", (unsigned int)ReadLength,
(unsigned int)SegmentSize, FileName);
BytesRemaining = 0;
}
}
Expand Down Expand Up @@ -629,7 +629,7 @@ bool MM_VerifyLoadFileSize(const char *FileName, const MM_LoadDumpFileHeader_t *
{
bool Valid = true;
int32 OS_Status;
uint32 ExpectedSize;
size_t ExpectedSize;
int32 ActualSize; /* The size returned by OS_stat is signed */
os_fstat_t FileStats;

Expand Down Expand Up @@ -663,8 +663,8 @@ bool MM_VerifyLoadFileSize(const char *FileName, const MM_LoadDumpFileHeader_t *
** the variable ActualSize to this function.
*/
CFE_EVS_SendEvent(MM_LD_FILE_SIZE_ERR_EID, CFE_EVS_EventType_ERROR,
"Load file size error: Reported by OS = %d Expected = %d File = '%s'", (int)ActualSize,
(int)ExpectedSize, FileName);
"Load file size error: Reported by OS = %d Expected = %u File = '%s'", (int)ActualSize,
(unsigned int)ExpectedSize, FileName);
}
}

Expand Down Expand Up @@ -725,7 +725,7 @@ bool MM_FillMemCmd(const CFE_SB_Buffer_t *BufPtr)
{
cpuaddr DestAddress = 0;
const MM_FillMemCmd_t *CmdPtr = (MM_FillMemCmd_t *)BufPtr;
uint16 ExpectedLength = sizeof(MM_FillMemCmd_t);
size_t ExpectedLength = sizeof(MM_FillMemCmd_t);
bool CmdResult = false;
MM_SymAddr_t DestSymAddress = CmdPtr->DestSymAddress;

Expand Down Expand Up @@ -800,7 +800,7 @@ bool MM_FillMem(cpuaddr DestAddress, const MM_FillMemCmd_t *CmdPtr)
{
uint16 i;
bool Valid = true;
uint32 BytesProcessed = 0;
size_t BytesProcessed = 0;
uint32 BytesRemaining = CmdPtr->NumOfBytes;
uint32 SegmentSize = MM_MAX_FILL_DATA_SEG;
uint8 *TargetPointer = (uint8 *)DestAddress;
Expand Down
20 changes: 10 additions & 10 deletions fsw/src/mm_mem16.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ bool MM_LoadMem16FromFile(osal_id_t FileHandle, const char *FileName, const MM_L
uint32 i;
int32 ReadLength;
CFE_Status_t PSP_Status = CFE_PSP_SUCCESS;
int32 BytesProcessed = 0;
size_t BytesProcessed = 0;
int32 BytesRemaining = FileHeader->NumOfBytes;
uint16 * DataPointer16 = (uint16 *)DestAddress;
uint16 * ioBuffer16 = (uint16 *)&MM_AppData.LoadBuffer[0];
uint32 SegmentSize = MM_MAX_LOAD_DATA_SEG;
size_t SegmentSize = MM_MAX_LOAD_DATA_SEG;
bool Valid = false;

while (BytesRemaining != 0)
Expand All @@ -73,8 +73,8 @@ bool MM_LoadMem16FromFile(osal_id_t FileHandle, const char *FileName, const MM_L
{
BytesRemaining = 0;
CFE_EVS_SendEvent(MM_OS_READ_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_read error received: RC = 0x%08X Expected = %d File = '%s'", (unsigned int)ReadLength,
(int)SegmentSize, FileName);
"OS_read error received: RC = 0x%08X Expected = %u File = '%s'", (unsigned int)ReadLength,
(unsigned int)SegmentSize, FileName);
}
else
{
Expand Down Expand Up @@ -138,11 +138,11 @@ bool MM_DumpMem16ToFile(osal_id_t FileHandle, const char *FileName, const MM_Loa
int32 OS_Status;
CFE_Status_t PSP_Status = CFE_PSP_SUCCESS;
uint32 i;
uint32 BytesProcessed = 0;
size_t BytesProcessed = 0;
uint32 BytesRemaining = FileHeader->NumOfBytes;
uint16 * DataPointer16 = (uint16 *)(FileHeader->SymAddress.Offset);
uint16 * ioBuffer16 = (uint16 *)&MM_AppData.DumpBuffer[0];
uint32 SegmentSize = MM_MAX_DUMP_DATA_SEG;
size_t SegmentSize = MM_MAX_DUMP_DATA_SEG;

while (BytesRemaining != 0)
{
Expand Down Expand Up @@ -193,8 +193,8 @@ bool MM_DumpMem16ToFile(osal_id_t FileHandle, const char *FileName, const MM_Loa
Valid = false;
BytesRemaining = 0;
CFE_EVS_SendEvent(MM_OS_WRITE_EXP_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_write error received: RC = 0x%08X Expected = %d File = '%s'",
(unsigned int)OS_Status, (int)SegmentSize, FileName);
"OS_write error received: RC = 0x%08X Expected = %u File = '%s'",
(unsigned int)OS_Status, (unsigned int)SegmentSize, FileName);
}
}
}
Expand Down Expand Up @@ -222,12 +222,12 @@ bool MM_FillMem16(cpuaddr DestAddress, const MM_FillMemCmd_t *CmdPtr)
{
uint32 i;
CFE_Status_t PSP_Status = CFE_PSP_SUCCESS;
uint32 BytesProcessed = 0;
size_t BytesProcessed = 0;
uint32 BytesRemaining = CmdPtr->NumOfBytes;
uint32 NewBytesRemaining;
uint16 FillPattern16 = (uint16)CmdPtr->FillPattern;
uint16 * DataPointer16 = (uint16 *)DestAddress;
uint32 SegmentSize = MM_MAX_FILL_DATA_SEG;
size_t SegmentSize = MM_MAX_FILL_DATA_SEG;
bool Result = true;

/* Check fill size and warn if not a multiple of 2 */
Expand Down
20 changes: 10 additions & 10 deletions fsw/src/mm_mem32.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ bool MM_LoadMem32FromFile(osal_id_t FileHandle, const char *FileName, const MM_L
uint32 i;
int32 ReadLength;
CFE_Status_t PSP_Status = CFE_PSP_SUCCESS;
int32 BytesProcessed = 0;
size_t BytesProcessed = 0;
int32 BytesRemaining = FileHeader->NumOfBytes;
uint32 * DataPointer32 = (uint32 *)DestAddress;
uint32 * ioBuffer32 = (uint32 *)&MM_AppData.LoadBuffer[0];
uint32 SegmentSize = MM_MAX_LOAD_DATA_SEG;
size_t SegmentSize = MM_MAX_LOAD_DATA_SEG;
bool Valid = false;

while (BytesRemaining != 0)
Expand All @@ -73,8 +73,8 @@ bool MM_LoadMem32FromFile(osal_id_t FileHandle, const char *FileName, const MM_L
{
BytesRemaining = 0;
CFE_EVS_SendEvent(MM_OS_READ_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_read error received: RC = 0x%08X Expected = %d File = '%s'", (unsigned int)ReadLength,
(int)SegmentSize, FileName);
"OS_read error received: RC = 0x%08X Expected = %u File = '%s'", (unsigned int)ReadLength,
(unsigned int)SegmentSize, FileName);
}
else
{
Expand Down Expand Up @@ -138,11 +138,11 @@ bool MM_DumpMem32ToFile(osal_id_t FileHandle, const char *FileName, const MM_Loa
int32 OS_Status;
CFE_Status_t PSP_Status = CFE_PSP_SUCCESS;
uint32 i;
uint32 BytesProcessed = 0;
size_t BytesProcessed = 0;
uint32 BytesRemaining = FileHeader->NumOfBytes;
uint32 * DataPointer32 = (uint32 *)(FileHeader->SymAddress.Offset);
uint32 * ioBuffer32 = (uint32 *)&MM_AppData.DumpBuffer[0];
uint32 SegmentSize = MM_MAX_DUMP_DATA_SEG;
size_t SegmentSize = MM_MAX_DUMP_DATA_SEG;

while (BytesRemaining != 0)
{
Expand Down Expand Up @@ -194,8 +194,8 @@ bool MM_DumpMem32ToFile(osal_id_t FileHandle, const char *FileName, const MM_Loa
Valid = false;
BytesRemaining = 0;
CFE_EVS_SendEvent(MM_OS_WRITE_EXP_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_write error received: RC = 0x%08X Expected = %d File = '%s'",
(unsigned int)OS_Status, (int)SegmentSize, FileName);
"OS_write error received: RC = 0x%08X Expected = %u File = '%s'",
(unsigned int)OS_Status, (unsigned int)SegmentSize, FileName);
}
}
}
Expand Down Expand Up @@ -223,12 +223,12 @@ bool MM_FillMem32(cpuaddr DestAddress, const MM_FillMemCmd_t *CmdPtr)
{
uint32 i;
CFE_Status_t PSP_Status = CFE_PSP_SUCCESS;
uint32 BytesProcessed = 0;
size_t BytesProcessed = 0;
uint32 BytesRemaining = CmdPtr->NumOfBytes;
uint32 NewBytesRemaining;
uint32 FillPattern32 = CmdPtr->FillPattern;
uint32 * DataPointer32 = (uint32 *)(DestAddress);
uint32 SegmentSize = MM_MAX_FILL_DATA_SEG;
size_t SegmentSize = MM_MAX_FILL_DATA_SEG;
bool Result = true;

/* Check fill size and warn if not a multiple of 4 */
Expand Down
Loading

0 comments on commit 2c0f6e1

Please sign in to comment.