File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 1313 * ========================================================================== */
1414
1515#include "qcbor/qcbor_common.h"
16- #include <string.h>
16+ #include "UsefulBuf.h"
1717
1818#define ERR_TO_STR_CASE (errpart ) case errpart: return #errpart;
1919
@@ -77,14 +77,17 @@ qcbor_err_to_str(const QCBORError uErr) {
7777 if (uErr >= QCBOR_ERR_FIRST_USER_DEFINED && uErr <= QCBOR_ERR_LAST_USER_DEFINED ) {
7878 /* Static buffer is not thread safe, but this is only a diagnostic */
7979 static char buf [20 ];
80- strcpy (buf , "USER_DEFINED_" );
81- size_t uEndOffset = strlen (buf );
82- buf [uEndOffset ] = (char )(uErr /100 + '0' );
83- buf [uEndOffset + 1 ] = (char )(((uErr /10 ) % 10 ) + '0' );
84- buf [uEndOffset + 2 ] = (char )((uErr % 10 )+ '0' );
85- buf [uEndOffset + 3 ] = '\0' ;
86- return buf ;
80+ UsefulOutBuf OB ;
81+
82+ /* Make NULL-terminated string "USER_DEFINED_NNN" using UsefulOutBuf */
83+ UsefulOutBuf_Init (& OB , UsefulBuf_FROM_BYTE_ARRAY (buf ));
84+ UsefulOutBuf_AppendString (& OB , "USER_DEFINED_" );
85+ UsefulOutBuf_AppendByte (& OB , (uint8_t )(uErr /100 + '0' ));
86+ UsefulOutBuf_AppendByte (& OB , (uint8_t )(((uErr /10 ) % 10 ) + '0' ));
87+ UsefulOutBuf_AppendByte (& OB , (uint8_t )(((uErr /10 ) % 10 ) + '0' ));
88+ UsefulOutBuf_AppendByte (& OB , 0x00 );
8789
90+ return buf ;
8891 } else {
8992 return "Unidentified QCBOR error" ;
9093 }
You can’t perform that action at this time.
0 commit comments