Skip to content

Commit

Permalink
Merge pull request #7 from renesas/FSPRA-2552-TFM-update-2-0-0
Browse files Browse the repository at this point in the history
Fspra 2552 tfm update 2 0 0
  • Loading branch information
michaelthomasj authored May 28, 2024
2 parents b4b1fd0 + 4e926d6 commit 161ac46
Show file tree
Hide file tree
Showing 17 changed files with 775 additions and 419 deletions.
27 changes: 8 additions & 19 deletions generated/qcbor-src/inc/qcbor/UsefulBuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
when who what, where, why
-------- ---- --------------------------------------------------
19/12/2022 llundblade Document that adding empty data is allowed.
4/11/2022 llundblade Add GetOutPlace and Advance to UsefulOutBuf.
9/21/2021 llundbla Clarify UsefulOutBuf size calculation mode
8/8/2021 dthaler/llundbla Work with C++ without compiler extensions
Expand Down Expand Up @@ -673,15 +674,8 @@ static inline UsefulBuf UsefulBufC_Unconst(const UsefulBufC UBC)
{
UsefulBuf UB;

// See UsefulBuf_Unconst() implementation for comment on pragmas
#ifndef _MSC_VER
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-qual"
#endif
UB.ptr = (void *)UBC.ptr;
#ifndef _MSC_VER
#pragma GCC diagnostic pop
#endif
// See UsefulBuf_Unconst() implementation for comment
UB.ptr = (void *)(uintptr_t)UBC.ptr;

UB.len = UBC.len;

Expand Down Expand Up @@ -954,6 +948,8 @@ static inline int UsefulOutBuf_AtStart(UsefulOutBuf *pUOutBuf);
* Overlapping buffers are OK. @c NewData can point to data in the
* output buffer.
*
* NewData.len may be 0 in which case nothing will be inserted.
*
* If an error occurs, an error state is set in the @ref
* UsefulOutBuf. No error is returned. All subsequent attempts to add
* data will do nothing.
Expand Down Expand Up @@ -1759,16 +1755,9 @@ static inline UsefulBuf UsefulBuf_Unconst(const UsefulBufC UBC)
UsefulBuf UB;

/* -Wcast-qual is a good warning flag to use in general. This is
* the one place in UsefulBuf where it needs to be quieted. Since
* clang supports GCC pragmas, this works for clang too. */
#ifndef _MSC_VER
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-qual"
#endif
UB.ptr = (void *)UBC.ptr;
#ifndef _MSC_VER
#pragma GCC diagnostic pop
#endif
* the one place in UsefulBuf where it needs to be quieted.
*/
UB.ptr = (void *)(uintptr_t)UBC.ptr;

UB.len = UBC.len;

Expand Down
28 changes: 14 additions & 14 deletions generated/qcbor-src/src/UsefulBuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
when who what, where, why
-------- ---- ---------------------------------------------------
4/11/2022 llundblade Add GetOutPlace and Advance to UsefulOutBuf
19/12/2022 llundblade Don't pass NULL to memmove when adding empty data.
4/11/2022 llundblade Add GetOutPlace and Advance to UsefulOutBuf
3/6/2021 mcr/llundblade Fix warnings related to --Wcast-qual
01/28/2020 llundblade Refine integer signedness to quiet static analysis.
01/08/2020 llundblade Documentation corrections & improved code formatting.
Expand Down Expand Up @@ -254,22 +255,23 @@ void UsefulOutBuf_InsertUsefulBuf(UsefulOutBuf *pMe, UsefulBufC NewData, size_t
}

/* 3. Slide existing data to the right */
uint8_t *pSourceOfMove = ((uint8_t *)pMe->UB.ptr) + uInsertionPos; // PtrMath #1
size_t uNumBytesToMove = pMe->data_len - uInsertionPos; // PtrMath #2
uint8_t *pDestinationOfMove = pSourceOfMove + NewData.len; // PtrMath #3
if (!UsefulOutBuf_IsBufferNULL(pMe)) {
uint8_t *pSourceOfMove = ((uint8_t *)pMe->UB.ptr) + uInsertionPos; // PtrMath #1
size_t uNumBytesToMove = pMe->data_len - uInsertionPos; // PtrMath #2
uint8_t *pDestinationOfMove = pSourceOfMove + NewData.len; // PtrMath #3

if(uNumBytesToMove && pMe->UB.ptr) {
// To know memmove won't go off end of destination, see PtrMath #4
// Use memove because it handles overlapping buffers
memmove(pDestinationOfMove, pSourceOfMove, uNumBytesToMove);
}

/* 4. Put the new data in */
uint8_t *pInsertionPoint = ((uint8_t *)pMe->UB.ptr) + uInsertionPos; // PtrMath #5
if(pMe->UB.ptr) {
// To know memmove won't go off end of destination, see PtrMath #6
memmove(pInsertionPoint, NewData.ptr, NewData.len);
/* 4. Put the new data in */
uint8_t *pInsertionPoint = pSourceOfMove;
// To know memmove won't go off end of destination, see PtrMath #5
if(NewData.ptr != NULL) {
memmove(pInsertionPoint, NewData.ptr, NewData.len);
}
}

pMe->data_len += NewData.len;
}

Expand All @@ -295,9 +297,7 @@ void UsefulOutBuf_InsertUsefulBuf(UsefulOutBuf *pMe, UsefulBufC NewData, size_t
Check #3 allows Check #2 to be refactored as NewData.Len > (me->size - uInsertionPos)
This algebraically rearranges to me->size > uInsertionPos + NewData.len
PtrMath #5 is exactly the same as PtrMath #1
PtrMath #6 will never wrap under because
PtrMath #5 will never wrap under because
Calculation for extent of memove is uRoomInDestination = me->UB.len - uInsertionPos;
Check #1 makes sure me->data_len is less than me->size
Check #3 makes sure uInsertionPos is less than me->data_len
Expand Down
Loading

0 comments on commit 161ac46

Please sign in to comment.