From 55a463d178096d64b52bed98d478241aed46151a Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Tue, 13 Jun 2023 20:41:40 +1000 Subject: [PATCH] Fix #113, Use `size_t` for size parameters and variables --- fsw/src/ds_file.c | 16 ++++++++-------- fsw/src/ds_file.h | 2 +- fsw/src/ds_table.c | 6 +++--- fsw/src/ds_table.h | 4 ++-- unit-test/ds_file_tests.c | 2 +- unit-test/ds_table_tests.c | 4 ++-- unit-test/stubs/ds_file_stubs.c | 4 ++-- unit-test/stubs/ds_table_stubs.c | 8 ++++---- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/fsw/src/ds_file.c b/fsw/src/ds_file.c index b9fd4a4..307f4cf 100644 --- a/fsw/src/ds_file.c +++ b/fsw/src/ds_file.c @@ -340,7 +340,7 @@ void DS_FileSetupWrite(int32 FileIndex, const CFE_SB_Buffer_t *BufPtr) /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void DS_FileWriteData(int32 FileIndex, const void *FileData, uint32 DataLength) +void DS_FileWriteData(int32 FileIndex, const void *FileData, size_t DataLength) { DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex]; int32 Result; @@ -552,9 +552,9 @@ void DS_FileCreateDest(uint32 FileIndex) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void DS_FileCreateName(uint32 FileIndex) { - DS_DestFileEntry_t *DestFile = &DS_AppData.DestFileTblPtr->File[FileIndex]; - DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex]; - int32 TotalLength = 0; + DS_DestFileEntry_t *DestFile = &DS_AppData.DestFileTblPtr->File[FileIndex]; + DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex]; + size_t TotalLength; char Workname[2 * DS_TOTAL_FNAME_BUFSIZE]; char Sequence[DS_TOTAL_FNAME_BUFSIZE]; @@ -805,10 +805,10 @@ void DS_FileCloseDest(int32 FileIndex) /* ** Move file from working directory to downlink directory... */ - int32 OS_result; - int32 PathLength; - char *FileName; - char PathName[DS_TOTAL_FNAME_BUFSIZE]; + int32 OS_result; + size_t PathLength; + char * FileName; + char PathName[DS_TOTAL_FNAME_BUFSIZE]; /* ** First, close the file... diff --git a/fsw/src/ds_file.h b/fsw/src/ds_file.h index c26c9c5..87fcbf6 100644 --- a/fsw/src/ds_file.h +++ b/fsw/src/ds_file.h @@ -124,7 +124,7 @@ void DS_FileSetupWrite(int32 FileIndex, const CFE_SB_Buffer_t *BufPtr); * * \sa #DS_AppFileStatus_t, #DS_DestFileEntry_t */ -void DS_FileWriteData(int32 FileIndex, const void *FileData, uint32 DataLength); +void DS_FileWriteData(int32 FileIndex, const void *FileData, size_t DataLength); /** * \brief Write data storage file header diff --git a/fsw/src/ds_table.c b/fsw/src/ds_table.c index 2e9d3db..ed26e7e 100644 --- a/fsw/src/ds_table.c +++ b/fsw/src/ds_table.c @@ -639,11 +639,11 @@ bool DS_TableVerifyFilterEntry(DS_PacketEntry_t *PacketEntry, int32 TableIndex, /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -bool DS_TableEntryUnused(const void *TableEntry, int32 BufferSize) +bool DS_TableEntryUnused(const void *TableEntry, size_t BufferSize) { const char *Buffer = (char *)TableEntry; bool Result = true; - int32 i = 0; + uint32 i; for (i = 0; i < BufferSize; i++) { @@ -751,7 +751,7 @@ bool DS_TableVerifyState(uint16 EnableState) /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -bool DS_TableVerifySize(uint32 MaxFileSize) +bool DS_TableVerifySize(size_t MaxFileSize) { bool Result = true; diff --git a/fsw/src/ds_table.h b/fsw/src/ds_table.h index ac12f02..51039e4 100644 --- a/fsw/src/ds_table.h +++ b/fsw/src/ds_table.h @@ -229,7 +229,7 @@ bool DS_TableVerifyFilterEntry(DS_PacketEntry_t *PacketEntry, int32 TableIndex, * * \sa #DS_PacketEntry_t, #DS_FilterParms_t, #DS_DestFileEntry_t */ -bool DS_TableEntryUnused(const void *TableEntry, int32 BufferSize); +bool DS_TableEntryUnused(const void *TableEntry, size_t BufferSize); /** * \brief Verify destination file index @@ -354,7 +354,7 @@ bool DS_TableVerifyState(uint16 EnableState); * * \sa #DS_TableVerifyAge, #DS_TableVerifyCount, #DS_DestFileEntry_t */ -bool DS_TableVerifySize(uint32 MaxFileSize); +bool DS_TableVerifySize(size_t MaxFileSize); /** * \brief Verify destination file max age limit diff --git a/unit-test/ds_file_tests.c b/unit-test/ds_file_tests.c index 4fc8469..aec9c6d 100644 --- a/unit-test/ds_file_tests.c +++ b/unit-test/ds_file_tests.c @@ -335,7 +335,7 @@ void DS_FileWriteData_Test_Nominal(void) void DS_FileWriteData_Test_Error(void) { int32 FileIndex = 0; - uint32 DataLength = 10; + size_t DataLength = 10; size_t forced_Size = sizeof(DS_NoopCmd_t); CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(DS_CMD_MID); diff --git a/unit-test/ds_table_tests.c b/unit-test/ds_table_tests.c index 7b58da5..380632e 100644 --- a/unit-test/ds_table_tests.c +++ b/unit-test/ds_table_tests.c @@ -1214,7 +1214,7 @@ void DS_TableVerifyState_Test_Fail(void) void DS_TableVerifySize_Test_Nominal(void) { - uint32 MaxFileSize = DS_FILE_MIN_SIZE_LIMIT; + size_t MaxFileSize = DS_FILE_MIN_SIZE_LIMIT; /* Execute the function being tested */ UtAssert_BOOL_TRUE(DS_TableVerifySize(MaxFileSize)); @@ -1225,7 +1225,7 @@ void DS_TableVerifySize_Test_Nominal(void) void DS_TableVerifySize_Test_Fail(void) { - uint32 MaxFileSize = DS_FILE_MIN_SIZE_LIMIT - 1; + size_t MaxFileSize = DS_FILE_MIN_SIZE_LIMIT - 1; /* Execute the function being tested */ UtAssert_BOOL_FALSE(DS_TableVerifySize(MaxFileSize)); diff --git a/unit-test/stubs/ds_file_stubs.c b/unit-test/stubs/ds_file_stubs.c index 4b47a64..5c95993 100644 --- a/unit-test/stubs/ds_file_stubs.c +++ b/unit-test/stubs/ds_file_stubs.c @@ -143,11 +143,11 @@ void DS_FileUpdateHeader(int32 FileIndex) * Generated stub function for DS_FileWriteData() * ---------------------------------------------------- */ -void DS_FileWriteData(int32 FileIndex, const void *FileData, uint32 DataLength) +void DS_FileWriteData(int32 FileIndex, const void *FileData, size_t DataLength) { UT_GenStub_AddParam(DS_FileWriteData, int32, FileIndex); UT_GenStub_AddParam(DS_FileWriteData, const void *, FileData); - UT_GenStub_AddParam(DS_FileWriteData, uint32, DataLength); + UT_GenStub_AddParam(DS_FileWriteData, size_t, DataLength); UT_GenStub_Execute(DS_FileWriteData, Basic, NULL); } diff --git a/unit-test/stubs/ds_table_stubs.c b/unit-test/stubs/ds_table_stubs.c index 2e06e5a..5633256 100644 --- a/unit-test/stubs/ds_table_stubs.c +++ b/unit-test/stubs/ds_table_stubs.c @@ -73,12 +73,12 @@ void DS_TableCreateHash(void) * Generated stub function for DS_TableEntryUnused() * ---------------------------------------------------- */ -bool DS_TableEntryUnused(const void *TableEntry, int32 BufferSize) +bool DS_TableEntryUnused(const void *TableEntry, size_t BufferSize) { UT_GenStub_SetupReturnBuffer(DS_TableEntryUnused, bool); UT_GenStub_AddParam(DS_TableEntryUnused, const void *, TableEntry); - UT_GenStub_AddParam(DS_TableEntryUnused, int32, BufferSize); + UT_GenStub_AddParam(DS_TableEntryUnused, size_t, BufferSize); UT_GenStub_Execute(DS_TableEntryUnused, Basic, NULL); @@ -325,11 +325,11 @@ bool DS_TableVerifyParms(uint16 Algorithm_N, uint16 Algorithm_X, uint16 Algorith * Generated stub function for DS_TableVerifySize() * ---------------------------------------------------- */ -bool DS_TableVerifySize(uint32 MaxFileSize) +bool DS_TableVerifySize(size_t MaxFileSize) { UT_GenStub_SetupReturnBuffer(DS_TableVerifySize, bool); - UT_GenStub_AddParam(DS_TableVerifySize, uint32, MaxFileSize); + UT_GenStub_AddParam(DS_TableVerifySize, size_t, MaxFileSize); UT_GenStub_Execute(DS_TableVerifySize, Basic, NULL);