Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2375, Use size_t for variables/parameters representing size #2376

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix #2375, Use size_t for variables/parameters representing size
  • Loading branch information
thnkslprpt committed Jun 15, 2023
commit 99eb3c33614177bd9826a922cbbc1964f608483d
4 changes: 2 additions & 2 deletions modules/cfe_testcase/src/tbl_content_mang_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ void TblTest_GenerateTblFiles(void)
{
osal_id_t fh1 = OS_OBJECT_ID_UNDEFINED;
osal_id_t fh2 = OS_OBJECT_ID_UNDEFINED;
uint32 PartialOffset;
uint32 PartialSize;
size_t PartialOffset;
size_t PartialSize;
union
{
uint8 u8;
Expand Down
6 changes: 3 additions & 3 deletions modules/core_api/ut-stubs/src/cfe_sb_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
typedef struct
{
CFE_SB_MsgId_t MsgId;
uint32 UserLength;
uint32 TotalLength;
size_t UserLength;
size_t TotalLength;
uint16 CommandCode;
CFE_TIME_SysTime_t TimeStamp;
} CFE_SB_StubMsg_MetaData_t;
Expand Down Expand Up @@ -343,7 +343,7 @@ void UT_DefaultHandler_CFE_SB_GetUserData(void *UserObj, UT_EntryKey_t FuncKey,
CFE_MSG_Message_t *MsgPtr = UT_Hook_GetArgValueByName(Context, "MsgPtr", CFE_MSG_Message_t *);
uint8 * BytePtr;
void * Result;
uint16 HdrSize;
size_t HdrSize;

if (UT_Stub_CopyToLocal(UT_KEY(CFE_SB_GetUserData), &Result, sizeof(Result)) != sizeof(Result))
{
Expand Down
10 changes: 5 additions & 5 deletions modules/core_private/ut-stubs/inc/ut_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ typedef struct
{
CFE_SB_MsgId_t MsgId;
uint16 SnapshotOffset;
uint16 SnapshotSize;
size_t SnapshotSize;
uint16 Count;
void * SnapshotBuffer;
} UT_SoftwareBusSnapshot_Entry_t;
Expand Down Expand Up @@ -333,7 +333,7 @@ void UT_SetStatusBSPResetArea(int32 status, uint32 Signature, uint32 ClockSignal
** This function does not return a value.
**
******************************************************************************/
void UT_SetReadBuffer(void *Buff, int NumBytes);
void UT_SetReadBuffer(void *Buff, size_t NumBytes);

/*****************************************************************************/
/**
Expand All @@ -353,7 +353,7 @@ void UT_SetReadBuffer(void *Buff, int NumBytes);
** This function does not return a value.
**
******************************************************************************/
void UT_SetReadHeader(void *Hdr, int NumBytes);
void UT_SetReadHeader(void *Hdr, size_t NumBytes);

/*****************************************************************************/
/**
Expand Down Expand Up @@ -393,7 +393,7 @@ void UT_SetDummyFuncRtn(int Return);
** \sa
**
******************************************************************************/
void UT_SetSizeofESResetArea(int32 Size);
void UT_SetSizeofESResetArea(size_t Size);

/*****************************************************************************/
/**
Expand All @@ -411,7 +411,7 @@ void UT_SetSizeofESResetArea(int32 Size);
** This function does not return a value.
**
******************************************************************************/
uint8 *UT_SetCDSSize(int32 Size);
uint8 *UT_SetCDSSize(size_t Size);

/*****************************************************************************/
/**
Expand Down
18 changes: 9 additions & 9 deletions modules/core_private/ut-stubs/src/ut_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
static char UT_appname[80];
static char UT_subsys[5];
static CFE_ES_AppId_t UT_AppID;
static uint32 UT_LastCDSSize = 0;
static size_t UT_LastCDSSize = 0;

typedef union
{
Expand Down Expand Up @@ -310,15 +310,15 @@
/*
** Set the contents of the buffer to read
*/
void UT_SetReadBuffer(void *Buff, int NumBytes)
void UT_SetReadBuffer(void *Buff, size_t NumBytes)
{
UT_SetDataBuffer(UT_KEY(OS_read), Buff, NumBytes, true);
}

/*
** Set the contents of the header to read
*/
void UT_SetReadHeader(void *Hdr, int NumBytes)
void UT_SetReadHeader(void *Hdr, size_t NumBytes)
{
UT_SetDataBuffer(UT_KEY(CFE_FS_ReadHeader), Hdr, NumBytes, true);
}
Expand All @@ -334,7 +334,7 @@
/*
** Set the size of the ES reset area
*/
void UT_SetSizeofESResetArea(int32 Size)
void UT_SetSizeofESResetArea(size_t Size)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
UT_ResetState(UT_KEY(CFE_PSP_GetResetArea));
if (Size > 0)
Expand All @@ -351,12 +351,12 @@
/*
** Set the CDS size returned by the BSP
*/
uint8 *UT_SetCDSSize(int32 Size)
uint8 *UT_SetCDSSize(size_t Size)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
UT_ResetState(UT_KEY(CFE_PSP_GetCDSSize));
UT_ResetState(UT_KEY(CFE_PSP_ReadFromCDS));
UT_ResetState(UT_KEY(CFE_PSP_WriteToCDS));
if (Size <= 0)
if (Size == 0)
{
UT_LastCDSSize = 0;
return NULL;
Expand Down Expand Up @@ -507,7 +507,7 @@
** But on the upside this concession avoids a far more complicated issue of
** needing a fully-fledged implementation of printf in the OS_printf stub.
*/
static int UT_StrCmpFormatStr(const char *FormatStr, const char *TestStr, uint32 FormatLength, uint32 TestLength)
static int UT_StrCmpFormatStr(const char *FormatStr, const char *TestStr, size_t FormatLength, size_t TestLength)

Check notice

Code scanning / CodeQL

Function too long Note

UT_StrCmpFormatStr has too many lines (95, while 60 are allowed).

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
const char *ChunkStart;
const char *ChunkEnd;
Expand Down Expand Up @@ -607,13 +607,13 @@
* A string comparison function that will match exact strings only
* (Printf style conversion strings are compared literally)
*/
static int UT_StrCmpExact(const char *RefStr, const char *TestStr, uint32 RefLength, uint32 TestLength)
static int UT_StrCmpExact(const char *RefStr, const char *TestStr, size_t RefLength, size_t TestLength)
{
return (RefLength == TestLength && memcmp(RefStr, TestStr, RefLength) == 0);
}

static uint32 UT_GetMessageCount(const char *Msg, UT_Buffer_t *Buf,
int (*Comparator)(const char *, const char *, uint32, uint32))
int (*Comparator)(const char *, const char *, size_t, size_t))
{
uint32 Count = 0;
uint32 MsgLen = strlen(Msg);
Expand Down
2 changes: 1 addition & 1 deletion modules/es/fsw/src/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath)
const char *TokenList[CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE];
uint32 NumTokens;
uint32 NumLines;
uint32 BuffLen; /* Length of the current buffer */
size_t BuffLen; /* Length of the current buffer */
osal_id_t AppFile = OS_OBJECT_ID_UNDEFINED;
int32 Status;
int32 OsStatus;
Expand Down
2 changes: 1 addition & 1 deletion modules/es/fsw/src/cfe_es_start.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef struct
char ObjectName[OS_MAX_API_NAME]; /* task or OS object name */
CFE_ES_FuncPtrUnion_t FuncPtrUnion; /* task or function reference */
uint32 ObjectPriority; /* object priority */
uint32 ObjectSize; /* size used for stack, queue size, etc. */
size_t ObjectSize; /* size used for stack, queue size, etc. */
uint32 ObjectFlags; /* extra flags to pass */
} CFE_ES_ObjectTable_t;

Expand Down
12 changes: 6 additions & 6 deletions modules/es/fsw/src/cfe_es_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ int32 CFE_ES_QueryAllCmd(const CFE_ES_QueryAllCmd_t *data)
osal_id_t FileDescriptor = OS_OBJECT_ID_UNDEFINED;
uint32 i;
uint32 EntryCount = 0;
uint32 FileSize = 0;
size_t FileSize = 0;
int32 OsStatus;
int32 Result;
CFE_ES_AppInfo_t AppInfo;
Expand Down Expand Up @@ -1088,8 +1088,8 @@ int32 CFE_ES_QueryAllCmd(const CFE_ES_QueryAllCmd_t *data)
OS_close(FileDescriptor);
CFE_ES_Global.TaskData.CommandCounter++;
CFE_EVS_SendEvent(CFE_ES_ALL_APPS_EID, CFE_EVS_EventType_DEBUG,
"App Info file written to %s, Entries=%d, FileSize=%d", QueryAllFilename, (int)EntryCount,
(int)FileSize);
"App Info file written to %s, Entries=%d, FileSize=%lu", QueryAllFilename, (int)EntryCount,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be %zu and then you wouldn't have to cast FileSize at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is not all "c99" compilers recognize %zu yet.... Once we update to C11 then we should be able to use the z modifier. For now I prefer to keep the cast to unsigned long.

(unsigned long)FileSize);
}
else
{
Expand All @@ -1111,7 +1111,7 @@ int32 CFE_ES_QueryAllTasksCmd(const CFE_ES_QueryAllTasksCmd_t *data)
osal_id_t FileDescriptor = OS_OBJECT_ID_UNDEFINED;
uint32 i;
uint32 EntryCount = 0;
uint32 FileSize = 0;
size_t FileSize = 0;
int32 OsStatus;
int32 Result;
CFE_ES_TaskInfo_t TaskInfo;
Expand Down Expand Up @@ -1240,8 +1240,8 @@ int32 CFE_ES_QueryAllTasksCmd(const CFE_ES_QueryAllTasksCmd_t *data)
OS_close(FileDescriptor);
CFE_ES_Global.TaskData.CommandCounter++;
CFE_EVS_SendEvent(CFE_ES_TASKINFO_EID, CFE_EVS_EventType_DEBUG,
"Task Info file written to %s, Entries=%d, FileSize=%d", QueryAllFilename, (int)EntryCount,
(int)FileSize);
"Task Info file written to %s, Entries=%d, FileSize=%lu", QueryAllFilename, (int)EntryCount,
(unsigned long)FileSize);
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions modules/es/ut-coverage/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
}
}

void ES_UT_SetupCDSGlobal(uint32 CDS_Size)
void ES_UT_SetupCDSGlobal(size_t CDS_Size)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars;

Expand Down Expand Up @@ -1135,7 +1135,7 @@

void TestApps(void)
{
int NumBytes;
size_t NumBytes;
CFE_ES_AppInfo_t AppInfo;
CFE_ES_AppId_t AppId;
CFE_ES_TaskId_t TaskId;
Expand Down Expand Up @@ -3935,7 +3935,7 @@
osal_id_t TestObjId;
char AppName[OS_MAX_API_NAME + 12];
char SysLogBuf[CFE_TIME_PRINTED_STRING_SIZE + 20];
uint32 SysLogBufSize;
size_t SysLogBufSize;
uint32 StackBuf[8];
uint8 Data[12];
uint32 ResetType;
Expand Down Expand Up @@ -4678,7 +4678,7 @@
CFE_ES_CDSHandle_t CDSHandle;
CFE_ES_CDS_RegRec_t *UtCDSRegRecPtr;
uint32 i;
uint32 TempSize;
size_t TempSize;
uint8 BlockData[ES_UT_CDS_BLOCK_SIZE];

UtPrintf("Begin Test CDS");
Expand Down
6 changes: 3 additions & 3 deletions modules/evs/ut-coverage/evs_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
.SnapshotOffset = offsetof(CFE_EVS_LongEventTlm_t, Payload.PacketID.EventID),
.SnapshotSize = sizeof(uint16)};

static const UT_SoftwareBusSnapshot_Entry_t UT_EVS_SHORTFMT_SNAPSHOTDATA = {

Check notice

Code scanning / CodeQL

Variable scope too large Note

The variable UT_EVS_SHORTFMT_SNAPSHOTDATA is only accessed in
UT_EVS_DoDispatchCheckEventsShort
and should be scoped accordingly.
.MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_EVS_SHORT_EVENT_MSG_MID),
.SnapshotOffset = offsetof(CFE_EVS_ShortEventTlm_t, Payload.PacketID.EventID),
.SnapshotSize = sizeof(uint16)};
Expand Down Expand Up @@ -155,7 +155,7 @@
return StubRetcode;
}

static void UT_EVS_DoDispatchCheckEvents_Impl(void *MsgPtr, uint32 MsgSize, UT_TaskPipeDispatchId_t DispatchId,
static void UT_EVS_DoDispatchCheckEvents_Impl(void *MsgPtr, size_t MsgSize, UT_TaskPipeDispatchId_t DispatchId,

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
const UT_SoftwareBusSnapshot_Entry_t *SnapshotCfg,
UT_EVS_EventCapture_t * EventCapture)
{
Expand All @@ -172,13 +172,13 @@
UT_SetHookFunction(UT_KEY(CFE_SB_TransmitMsg), NULL, NULL);
}

static void UT_EVS_DoDispatchCheckEvents(void *MsgPtr, uint32 MsgSize, UT_TaskPipeDispatchId_t DispatchId,
static void UT_EVS_DoDispatchCheckEvents(void *MsgPtr, size_t MsgSize, UT_TaskPipeDispatchId_t DispatchId,
UT_EVS_EventCapture_t *EventCapture)
{
UT_EVS_DoDispatchCheckEvents_Impl(MsgPtr, MsgSize, DispatchId, &UT_EVS_LONGFMT_SNAPSHOTDATA, EventCapture);
}

static void UT_EVS_DoDispatchCheckEventsShort(void *MsgPtr, uint32 MsgSize, UT_TaskPipeDispatchId_t DispatchId,
static void UT_EVS_DoDispatchCheckEventsShort(void *MsgPtr, size_t MsgSize, UT_TaskPipeDispatchId_t DispatchId,
UT_EVS_EventCapture_t *EventCapture)
{
UT_EVS_DoDispatchCheckEvents_Impl(MsgPtr, MsgSize, DispatchId, &UT_EVS_SHORTFMT_SNAPSHOTDATA, EventCapture);
Expand Down
2 changes: 1 addition & 1 deletion modules/sb/fsw/src/cfe_sb_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct
{
const char *Filename; /* File name for error reporting */
osal_id_t Fd; /* File id for writing */
uint32 FileSize; /* File size for reporting */
size_t FileSize; /* File size for reporting */
uint32 EntryCount; /* Entry count for reporting */
int32 Status; /* File write status */
} CFE_SB_FileWriteCallback_t;
Expand Down
4 changes: 2 additions & 2 deletions modules/sb/ut-coverage/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -3202,7 +3202,7 @@ void Test_TransmitMsg_GetPoolBufErr(void)
*/
void Test_AllocateMessageBuffer(void)
{
uint16 MsgSize = 10;
size_t MsgSize = 10;
uint32 MemUse;

/* Attempt to allocate a message buffer greater than the max size */
Expand Down Expand Up @@ -3394,7 +3394,7 @@ void Test_ReleaseMessageBuffer(void)
CFE_SB_Buffer_t *ZeroCpyMsgPtr2 = NULL;
CFE_SB_Buffer_t *ZeroCpyMsgPtr3 = NULL;
CFE_SB_BufferD_t BadBufferDesc;
uint16 MsgSize = 10;
size_t MsgSize = 10;

ZeroCpyMsgPtr1 = CFE_SB_AllocateMessageBuffer(MsgSize);
ZeroCpyMsgPtr2 = CFE_SB_AllocateMessageBuffer(MsgSize);
Expand Down
2 changes: 1 addition & 1 deletion modules/tbl/ut-coverage/tbl_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void Test_CFE_TBL_ActivateCmd(void)
*/
void Test_CFE_TBL_DumpToFile(void)
{
uint32 TblSizeInBytes = 9;
size_t TblSizeInBytes = 9;

UtPrintf("Begin Test Dump to File");

Expand Down