Skip to content

Commit

Permalink
Merge pull request #93 from thnkslprpt/fix-92-use-size_t-for-sizes
Browse files Browse the repository at this point in the history
Fix #92, Use size_t for 'size' variables
  • Loading branch information
dzbaker authored Mar 30, 2023
2 parents 274c8bf + 059961a commit 7611550
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 68 deletions.
2 changes: 1 addition & 1 deletion fsw/inc/fm_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* @file
* Specification for the CFS File Manager Event Identifers.
* Specification for the CFS File Manager Event Identifiers.
*/
#ifndef FM_EVENTS_H
#define FM_EVENTS_H
Expand Down
30 changes: 15 additions & 15 deletions fsw/src/fm_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

/************************************************************************
** OSAL Compatibility for directory name access
** New OSAL version have an access macro to get the string. If that
** New OSAL version has an access macro to get the string. If that
** macro is defined, use it, otherwise assume "d_name" structure member.
*************************************************************************/
#ifndef OS_DIRENTRY_NAME
Expand Down Expand Up @@ -195,7 +195,7 @@ void FM_ChildProcess(void)
const char * TaskText = "Child Task";
FM_ChildQueueEntry_t *CmdArgs = &FM_GlobalData.ChildQueue[FM_GlobalData.ChildReadIndex];

/* Invoke the command specific handler */
/* Invoke the command-specific handler */
switch (CmdArgs->CommandCode)
{
case FM_COPY_FILE_CC:
Expand Down Expand Up @@ -448,7 +448,7 @@ void FM_ChildDeleteAllFilesCmd(FM_ChildQueueEntry_t *CmdArgs)
char Filename[2 * OS_MAX_PATH_LEN] = "";

/*
** Command argument useage for this command:
** Command argument usage for this command:
**
** CmdArgs->CommandCode = FM_DELETE_ALL_FILES_CC
** CmdArgs->Source1 = directory name
Expand Down Expand Up @@ -815,7 +815,7 @@ void FM_ChildFileInfoCmd(FM_ChildQueueEntry_t *CmdArgs)
FM_GlobalData.ChildCurrentCC = CmdArgs->CommandCode;

/*
** Command argument useage for this command:
** Command argument usage for this command:
**
** CmdArgs->CommandCode = FM_GET_DIR_LIST_FILE_CC
** CmdArgs->Source1 = name of directory or file
Expand Down Expand Up @@ -1090,7 +1090,7 @@ void FM_ChildDirListFileCmd(const FM_ChildQueueEntry_t *CmdArgs)
FM_GlobalData.ChildCurrentCC = CmdArgs->CommandCode;

/*
** Command argument useage for this command:
** Command argument usage for this command:
**
** CmdArgs->CommandCode = FM_GET_DIR_LIST_FILE_CC
** CmdArgs->Source1 = directory name
Expand Down Expand Up @@ -1147,8 +1147,8 @@ void FM_ChildDirListPktCmd(const FM_ChildQueueEntry_t *CmdArgs)
os_dirent_t DirEntry;
int32 ListIndex = 0;
FM_DirListEntry_t *ListEntry = NULL;
int32 PathLength = 0;
int32 EntryLength = 0;
size_t PathLength = 0;
size_t EntryLength = 0;
int32 FilesTillSleep = FM_CHILD_STAT_SLEEP_FILECOUNT;
int32 Status;

Expand All @@ -1160,7 +1160,7 @@ void FM_ChildDirListPktCmd(const FM_ChildQueueEntry_t *CmdArgs)
FM_GlobalData.ChildCurrentCC = CmdArgs->CommandCode;

/*
** Command argument useage for this command:
** Command argument usage for this command:
**
** CmdArgs->CommandCode = FM_GET_DIR_LIST_PKT_CC
** CmdArgs->Source1 = directory name
Expand Down Expand Up @@ -1209,7 +1209,7 @@ void FM_ChildDirListPktCmd(const FM_ChildQueueEntry_t *CmdArgs)
/* Do not count the "." and ".." directory entries */
ReportPtr->TotalFiles++;

/* Start collecting directory entries at command specified offset */
/* Start collecting directory entries at command-specified offset */
/* Stop collecting directory entries when telemetry packet is full */
if ((ReportPtr->TotalFiles > ReportPtr->FirstFile) &&
(ReportPtr->PacketFiles < FM_DIR_LIST_PKT_ENTRIES))
Expand Down Expand Up @@ -1335,7 +1335,7 @@ bool FM_ChildDirListFileInit(osal_id_t *FileHandlePtr, const char *Directory, co
strncpy(FM_GlobalData.DirListFileStats.DirName, Directory, OS_MAX_PATH_LEN - 1);
FM_GlobalData.DirListFileStats.DirName[OS_MAX_PATH_LEN - 1] = '\0';

/* Write blank FM directory statistics structure as a place holder */
/* Write blank FM directory statistics structure as a placeholder */
BytesWritten = OS_write(FileHandle, &FM_GlobalData.DirListFileStats, sizeof(FM_DirListFileStats_t));
if (BytesWritten == sizeof(FM_DirListFileStats_t))
{
Expand Down Expand Up @@ -1393,13 +1393,13 @@ void FM_ChildDirListFileLoop(osal_id_t DirId, osal_id_t FileHandle, const char *
const char *Filename, uint8 getSizeTimeMode)
{
const char * CmdText = "Directory List to File";
int32 WriteLength = sizeof(FM_DirListEntry_t);
size_t WriteLength = sizeof(FM_DirListEntry_t);
bool ReadingDirectory = true;
bool CommandResult = true;
uint32 DirEntries = 0;
uint32 FileEntries = 0;
int32 EntryLength = 0;
int32 PathLength = 0;
size_t EntryLength = 0;
size_t PathLength = 0;
int32 BytesWritten = 0;
int32 FilesTillSleep = FM_CHILD_STAT_SLEEP_FILECOUNT;
int32 Status = 0;
Expand Down Expand Up @@ -1445,7 +1445,7 @@ void FM_ChildDirListFileLoop(osal_id_t DirId, osal_id_t FileHandle, const char *

/*
* Populate directory list file entry -
* Note this is guaranteed to be null terminated due to the memset()
* Note this is guaranteed to be null-terminated due to the memset()
* this will leave at least one null char after the string.
*/
memset(&DirListData, 0, sizeof(DirListData));
Expand Down Expand Up @@ -1491,7 +1491,7 @@ void FM_ChildDirListFileLoop(osal_id_t DirId, osal_id_t FileHandle, const char *
FM_GlobalData.DirListFileStats.DirEntries = DirEntries;
FM_GlobalData.DirListFileStats.FileEntries = FileEntries;

/* Back up to the start of the statisitics data */
/* Back up to the start of the statistics data */
OS_lseek(FileHandle, sizeof(CFE_FS_Header_t), OS_SEEK_SET);

/* Write an updated version of the statistics data */
Expand Down
28 changes: 14 additions & 14 deletions fsw/src/fm_cmd_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void SearchOpenFileData(osal_id_t ObjId, void *CallbackArg)
}
}

uint32 FM_GetFilenameState(const char *Filename, uint32 BufferSize, bool FileInfoCmd)
uint32 FM_GetFilenameState(const char *Filename, size_t BufferSize, bool FileInfoCmd)
{
os_fstat_t FileStatus;
uint32 FilenameState = FM_NAME_IS_INVALID;
Expand Down Expand Up @@ -217,7 +217,7 @@ uint32 FM_GetFilenameState(const char *Filename, uint32 BufferSize, bool FileInf
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

uint32 FM_VerifyNameValid(const char *Name, uint32 BufferSize, uint32 EventID, const char *CmdText)
uint32 FM_VerifyNameValid(const char *Name, size_t BufferSize, uint32 EventID, const char *CmdText)
{
char LocalFile[1 + OS_MAX_PATH_LEN];
uint32 FilenameState = FM_NAME_IS_INVALID;
Expand All @@ -228,8 +228,8 @@ uint32 FM_VerifyNameValid(const char *Name, uint32 BufferSize, uint32 EventID, c
if (FilenameState == FM_NAME_IS_INVALID)
{
/*
* This function provided by SB will copy the string from a fixed size buffer,
* and always ensures the result is null terminated
* This function provided by SB will copy the string from a fixed-size buffer,
* and always ensures the result is null-terminated
*/
CFE_SB_MessageStringGet(LocalFile, Name, NULL, sizeof(LocalFile), BufferSize);
CFE_EVS_SendEvent(EventID, CFE_EVS_EventType_ERROR, "%s error: invalid name: name = %s", CmdText, LocalFile);
Expand All @@ -244,7 +244,7 @@ uint32 FM_VerifyNameValid(const char *Name, uint32 BufferSize, uint32 EventID, c
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

bool FM_VerifyFileState(FM_File_States State, const char *Filename, uint32 BufferSize, uint32 EventID,
bool FM_VerifyFileState(FM_File_States State, const char *Filename, size_t BufferSize, uint32 EventID,
const char *CmdText)
{
bool Result = false;
Expand Down Expand Up @@ -337,8 +337,8 @@ bool FM_VerifyFileState(FM_File_States State, const char *Filename, uint32 Buffe
if (!Result)
{
/*
* This function provided by SB will copy the string from a fixed size buffer,
* and always ensures the result is null terminated
* This function provided by SB will copy the string from a fixed-size buffer,
* and always ensures the result is null-terminated
*/
CFE_SB_MessageStringGet(LocalFile, Filename, NULL, sizeof(LocalFile), BufferSize);
CFE_EVS_SendEvent((EventID + ErrorCode), CFE_EVS_EventType_ERROR, "%s error: %s: name = %s", CmdText, ErrorDesc,
Expand All @@ -354,7 +354,7 @@ bool FM_VerifyFileState(FM_File_States State, const char *Filename, uint32 Buffe
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

bool FM_VerifyFileClosed(const char *Filename, uint32 BufferSize, uint32 EventID, const char *CmdText)
bool FM_VerifyFileClosed(const char *Filename, size_t BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_FILE_CLOSED, Filename, BufferSize, EventID, CmdText);
}
Expand All @@ -365,7 +365,7 @@ bool FM_VerifyFileClosed(const char *Filename, uint32 BufferSize, uint32 EventID
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

bool FM_VerifyFileExists(const char *Filename, uint32 BufferSize, uint32 EventID, const char *CmdText)
bool FM_VerifyFileExists(const char *Filename, size_t BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_FILE_EXISTS, Filename, BufferSize, EventID, CmdText);
}
Expand All @@ -376,7 +376,7 @@ bool FM_VerifyFileExists(const char *Filename, uint32 BufferSize, uint32 EventID
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

bool FM_VerifyFileNoExist(const char *Filename, uint32 BufferSize, uint32 EventID, const char *CmdText)
bool FM_VerifyFileNoExist(const char *Filename, size_t BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_FILE_NOEXIST, Filename, BufferSize, EventID, CmdText);
}
Expand All @@ -387,7 +387,7 @@ bool FM_VerifyFileNoExist(const char *Filename, uint32 BufferSize, uint32 EventI
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

bool FM_VerifyFileNotOpen(const char *Filename, uint32 BufferSize, uint32 EventID, const char *CmdText)
bool FM_VerifyFileNotOpen(const char *Filename, size_t BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_FILE_NOTOPEN, Filename, BufferSize, EventID, CmdText);
}
Expand All @@ -398,7 +398,7 @@ bool FM_VerifyFileNotOpen(const char *Filename, uint32 BufferSize, uint32 EventI
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

bool FM_VerifyDirExists(const char *Directory, uint32 BufferSize, uint32 EventID, const char *CmdText)
bool FM_VerifyDirExists(const char *Directory, size_t BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_DIR_EXISTS, Directory, BufferSize, EventID, CmdText);
}
Expand All @@ -409,7 +409,7 @@ bool FM_VerifyDirExists(const char *Directory, uint32 BufferSize, uint32 EventID
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

bool FM_VerifyDirNoExist(const char *Name, uint32 BufferSize, uint32 EventID, const char *CmdText)
bool FM_VerifyDirNoExist(const char *Name, size_t BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_DIR_NOEXIST, Name, BufferSize, EventID, CmdText);
}
Expand Down Expand Up @@ -506,7 +506,7 @@ void FM_AppendPathSep(char *Directory, uint32 BufferSize)
** the string is both non-zero and less than the size
** of the string buffer.
*/
uint32 StringLength = 0;
size_t StringLength = 0;

StringLength = strlen(Directory);

Expand Down
Loading

0 comments on commit 7611550

Please sign in to comment.