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 #1443, Replace for loop copy with single memcpy #2267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 #1443, Replace for loop copy with single memcpy
  • Loading branch information
thnkslprpt committed Mar 28, 2023
commit eec960cb3249bdeb4ff15f73d84f4c1d4c18a779
14 changes: 4 additions & 10 deletions modules/core_api/ut-stubs/src/cfe_fs_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void UT_DefaultHandler_CFE_FS_ExtractFilenameFromPath(void *UserObj, UT_EntryKey
const char *OriginalPath = UT_Hook_GetArgValueByName(Context, "OriginalPath", const char *);
char * FileNameOnly = UT_Hook_GetArgValueByName(Context, "FileNameOnly", char *);

int i, j;
int i;
int StringLength;
int DirMarkIdx;
int32 status;
Expand Down Expand Up @@ -269,15 +269,9 @@ void UT_DefaultHandler_CFE_FS_ExtractFilenameFromPath(void *UserObj, UT_EntryKey
if (DirMarkIdx > 0)
{
/* Extract the filename portion */
j = 0;

for (i = DirMarkIdx + 1; i < StringLength; i++)
{
FileNameOnly[j] = OriginalPath[i];
j++;
}

FileNameOnly[j] = '\0';
i = DirMarkIdx + 1;
memcpy(FileNameOnly, OriginalPath + i, StringLength - i);
FileNameOnly[(StringLength - i) + 1] = '\0';
}
else
{
Expand Down
12 changes: 4 additions & 8 deletions modules/fs/fsw/src/cfe_fs_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ int32 CFE_FS_ParseInputFileName(char *OutputBuffer, const char *InputName, size_
*-----------------------------------------------------------------*/
CFE_Status_t CFE_FS_ExtractFilenameFromPath(const char *OriginalPath, char *FileNameOnly)
{
uint32 i, j;
uint32 i;
int StringLength;
int DirMarkIdx;
int32 ReturnCode;
Expand Down Expand Up @@ -640,13 +640,9 @@ CFE_Status_t CFE_FS_ExtractFilenameFromPath(const char *OriginalPath, char *File
/*
** Extract the filename portion
*/
j = 0;
for (i = DirMarkIdx + 1; i < StringLength; i++)
{
FileNameOnly[j] = OriginalPath[i];
j++;
}
FileNameOnly[j] = '\0';
i = DirMarkIdx + 1;
memcpy(FileNameOnly, OriginalPath + i, StringLength - i);
FileNameOnly[(StringLength - i) + 1] = '\0';

ReturnCode = CFE_SUCCESS;
}
Expand Down