Useful_Set interface changed to be more in line with UsefulBulf conventions
diff --git a/inc/UsefulBuf.h b/inc/UsefulBuf.h
index c2b2e09..b74aa35 100644
--- a/inc/UsefulBuf.h
+++ b/inc/UsefulBuf.h
@@ -406,9 +406,10 @@
this will crash if NULL or invalid.
*/
-static inline void UsefulBuf_Set(UsefulBuf *pDest, uint8_t value)
+static inline UsefulBufC UsefulBuf_Set(UsefulBuf pDest, uint8_t value)
{
- memset(pDest->ptr, value, pDest->len);
+ memset(pDest.ptr, value, pDest.len);
+ return (UsefulBufC){pDest.ptr, pDest.len};
}
diff --git a/test/UsefulBuf_Tests.c b/test/UsefulBuf_Tests.c
index f79c08c..fef885d 100644
--- a/test/UsefulBuf_Tests.c
+++ b/test/UsefulBuf_Tests.c
@@ -394,11 +394,11 @@
// Set 100 bytes of '+'; validated a few tests later
MakeUsefulBufOnStack(Temp, 100);
- UsefulBuf_Set(&Temp, '+');
+ UsefulBufC TempC = UsefulBuf_Set(Temp, '+');
// Try to copy into a buf that is too small and see failure
UsefulBuf_MakeStackUB(Temp2, 99);
- if(!UsefulBuf_IsNULLC(UsefulBuf_Copy(Temp2, UsefulBuf_Const(Temp)))) {
+ if(!UsefulBuf_IsNULLC(UsefulBuf_Copy(Temp2, TempC))) {
return "Copy should have failed";
}
@@ -433,17 +433,17 @@
// Try to copy into a NULL/empty buf and see failure
UsefulBuf UBNull = NULLUsefulBuf;
- if(!UsefulBuf_IsNULLC(UsefulBuf_Copy(UBNull, UsefulBuf_Const(Temp)))) {
+ if(!UsefulBuf_IsNULLC(UsefulBuf_Copy(UBNull, TempC))) {
return "Copy to NULL should have failed";
}
// Try to set a NULL/empty buf; nothing should happen
- UsefulBuf_Set(&UBNull, '+'); // This will crash on failure
+ UsefulBuf_Set(UBNull, '+'); // This will crash on failure
// Copy successfully to a buffer
MakeUsefulBufOnStack(Temp3, 101);
- if(UsefulBuf_IsNULLC(UsefulBuf_Copy(Temp3, UsefulBuf_Const(Temp)))) {
+ if(UsefulBuf_IsNULLC(UsefulBuf_Copy(Temp3, TempC))) {
return "Copy should not have failed";
}
@@ -461,7 +461,7 @@
};
UsefulBufC Expected = ByteArrayLiteralToUsefulBufC(pExpected);
// This validates comparison for equality and the UsefulBuf_Set
- if(UsefulBuf_Compare(Expected, UsefulBuf_Const(Temp))) {
+ if(UsefulBuf_Compare(Expected, TempC)) {
return "Set / Copy / Compare failed";
}
diff --git a/test/qcbor_decode_malloc_tests.c b/test/qcbor_decode_malloc_tests.c
index 91fff98..a290b33 100644
--- a/test/qcbor_decode_malloc_tests.c
+++ b/test/qcbor_decode_malloc_tests.c
@@ -66,7 +66,7 @@
if((nCBORError = QCBORDecode_GetNext(&DC, &Item4)))
return nCBORError;
- UsefulBuf_Set(&CopyOfStorage, '_');
+ UsefulBuf_Set(CopyOfStorage, '_');
if(Item1.uLabelType != QCBOR_TYPE_TEXT_STRING ||
Item1.label.string.len != 13 ||
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 0bc2525..9e61dd5 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -2171,7 +2171,7 @@
if((nCBORError = QCBORDecode_GetNext(&DC, &Item4)))
return nCBORError;
- UsefulBuf_Set(&CopyOfStorage, '_');
+ UsefulBuf_Set(CopyOfStorage, '_');
if(Item1.uLabelType != QCBOR_TYPE_TEXT_STRING ||
Item1.label.string.len != 13 ||