From ade8d8da69b8c9fc3e3521fb52b3277db8ee72f6 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Tue, 28 Jun 2022 05:30:58 +0800 Subject: [PATCH] Call memcpy to copy a struct (#25) * Call memcpy to copy a struct * Insert 2 filler bytes to get better alignment. * Sorry, typo * Call sizeof with brackets - 1 Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> * Call sizeof with brackets - 2 Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> Co-authored-by: Hein Tibosch Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> --- ff_stdio.c | 10 ++++++++-- include/ff_dir.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ff_stdio.c b/ff_stdio.c index 0ea0791..f6317c0 100755 --- a/ff_stdio.c +++ b/ff_stdio.c @@ -1489,8 +1489,14 @@ int ff_findnext( FF_FindData_t * pxFindData ) pxFindData->xDirectoryEntry.xCreateTime.Hour = ( uint16_t ) xTimeStruct.tm_hour; /* Hour (0 - 23). */ pxFindData->xDirectoryEntry.xCreateTime.Minute = ( uint16_t ) xTimeStruct.tm_min; /* Min (0 - 59). */ pxFindData->xDirectoryEntry.xCreateTime.Second = ( uint16_t ) xTimeStruct.tm_sec; /* Second (0 - 59). */ - pxFindData->xDirectoryEntry.xModifiedTime = pxFindData->xDirectoryEntry.xCreateTime; /* Date and Time Modified. */ - pxFindData->xDirectoryEntry.xAccessedTime = pxFindData->xDirectoryEntry.xCreateTime; /* Date of Last Access. */ + /* Date and Time Modified. */ + memcpy( &( pxFindData->xDirectoryEntry.xModifiedTime ), + &( pxFindData->xDirectoryEntry.xCreateTime ), + sizeof( pxFindData->xDirectoryEntry.xModifiedTime ) ); + /* Date of Last Access. */ + memcpy( &( pxFindData->xDirectoryEntry.xAccessedTime ), + &( pxFindData->xDirectoryEntry.xCreateTime ), + sizeof( pxFindData->xDirectoryEntry.xAccessedTime ) ); } } #endif /* ffconfigTIME_SUPPORT */ diff --git a/include/ff_dir.h b/include/ff_dir.h index 39a6305..cffa5e6 100755 --- a/include/ff_dir.h +++ b/include/ff_dir.h @@ -64,6 +64,8 @@ typedef struct uint32_t ulAddrCurrentCluster; uint32_t ulDirCluster; uint16_t usCurrentItem; + /* Insert 2 bytes to make the next struct 32-bit aligned. */ + uint16_t usFillerBytes; /* End Book Keeping. */ #if ( ffconfigTIME_SUPPORT != 0 )