99#include "cbor/internal/builder_callbacks.h"
1010#include "cbor/internal/loaders.h"
1111
12- cbor_item_t * cbor_load (cbor_data source , size_t source_size ,
13- struct cbor_load_result * result ) {
12+ cbor_item_t * cbor_load (cbor_data source , size_t source_size ,
13+ struct cbor_load_result * result ) {
1414 /* Context stack */
1515 static struct cbor_callbacks callbacks = {
1616 .uint8 = & cbor_builder_uint8_callback ,
@@ -114,8 +114,8 @@ cbor_item_t *cbor_load(cbor_data source, size_t source_size,
114114 return NULL ;
115115}
116116
117- static cbor_item_t * _cbor_copy_int (cbor_item_t * item , bool negative ) {
118- cbor_item_t * res = NULL ;
117+ static cbor_item_t * _cbor_copy_int (cbor_item_t * item , bool negative ) {
118+ cbor_item_t * res = NULL ;
119119 switch (cbor_int_get_width (item )) {
120120 case CBOR_INT_8 :
121121 res = cbor_build_uint8 (cbor_get_uint8 (item ));
@@ -136,8 +136,7 @@ static cbor_item_t *_cbor_copy_int(cbor_item_t *item, bool negative) {
136136 return res ;
137137}
138138
139- static cbor_item_t * _cbor_copy_float_ctrl (cbor_item_t * item ) {
140- // cppcheck-suppress missingReturn
139+ static cbor_item_t * _cbor_copy_float_ctrl (cbor_item_t * item ) {
141140 switch (cbor_float_get_width (item )) {
142141 case CBOR_FLOAT_0 :
143142 return cbor_build_ctrl (cbor_ctrl_value (item ));
@@ -147,11 +146,13 @@ static cbor_item_t *_cbor_copy_float_ctrl(cbor_item_t *item) {
147146 return cbor_build_float4 (cbor_float_get_float4 (item ));
148147 case CBOR_FLOAT_64 :
149148 return cbor_build_float8 (cbor_float_get_float8 (item ));
149+ default :
150+ _CBOR_UNREACHABLE ;
151+ return NULL ;
150152 }
151153}
152154
153- cbor_item_t * cbor_copy (cbor_item_t * item ) {
154- // cppcheck-suppress missingReturn
155+ cbor_item_t * cbor_copy (cbor_item_t * item ) {
155156 switch (cbor_typeof (item )) {
156157 case CBOR_TYPE_UINT :
157158 return _cbor_copy_int (item , false);
@@ -162,13 +163,13 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
162163 return cbor_build_bytestring (cbor_bytestring_handle (item ),
163164 cbor_bytestring_length (item ));
164165 } else {
165- cbor_item_t * res = cbor_new_indefinite_bytestring ();
166+ cbor_item_t * res = cbor_new_indefinite_bytestring ();
166167 if (res == NULL ) {
167168 return NULL ;
168169 }
169170
170171 for (size_t i = 0 ; i < cbor_bytestring_chunk_count (item ); i ++ ) {
171- cbor_item_t * chunk_copy =
172+ cbor_item_t * chunk_copy =
172173 cbor_copy (cbor_bytestring_chunks_handle (item )[i ]);
173174 if (chunk_copy == NULL ) {
174175 cbor_decref (& res );
@@ -185,16 +186,16 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
185186 }
186187 case CBOR_TYPE_STRING :
187188 if (cbor_string_is_definite (item )) {
188- return cbor_build_stringn ((const char * )cbor_string_handle (item ),
189+ return cbor_build_stringn ((const char * )cbor_string_handle (item ),
189190 cbor_string_length (item ));
190191 } else {
191- cbor_item_t * res = cbor_new_indefinite_string ();
192+ cbor_item_t * res = cbor_new_indefinite_string ();
192193 if (res == NULL ) {
193194 return NULL ;
194195 }
195196
196197 for (size_t i = 0 ; i < cbor_string_chunk_count (item ); i ++ ) {
197- cbor_item_t * chunk_copy =
198+ cbor_item_t * chunk_copy =
198199 cbor_copy (cbor_string_chunks_handle (item )[i ]);
199200 if (chunk_copy == NULL ) {
200201 cbor_decref (& res );
@@ -210,7 +211,7 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
210211 return res ;
211212 }
212213 case CBOR_TYPE_ARRAY : {
213- cbor_item_t * res ;
214+ cbor_item_t * res ;
214215 if (cbor_array_is_definite (item )) {
215216 res = cbor_new_definite_array (cbor_array_size (item ));
216217 } else {
@@ -221,7 +222,7 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
221222 }
222223
223224 for (size_t i = 0 ; i < cbor_array_size (item ); i ++ ) {
224- cbor_item_t * entry_copy = cbor_copy (cbor_move (cbor_array_get (item , i )));
225+ cbor_item_t * entry_copy = cbor_copy (cbor_move (cbor_array_get (item , i )));
225226 if (entry_copy == NULL ) {
226227 cbor_decref (& res );
227228 return NULL ;
@@ -236,7 +237,7 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
236237 return res ;
237238 }
238239 case CBOR_TYPE_MAP : {
239- cbor_item_t * res ;
240+ cbor_item_t * res ;
240241 if (cbor_map_is_definite (item )) {
241242 res = cbor_new_definite_map (cbor_map_size (item ));
242243 } else {
@@ -246,14 +247,14 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
246247 return NULL ;
247248 }
248249
249- struct cbor_pair * it = cbor_map_handle (item );
250+ struct cbor_pair * it = cbor_map_handle (item );
250251 for (size_t i = 0 ; i < cbor_map_size (item ); i ++ ) {
251- cbor_item_t * key_copy = cbor_copy (it [i ].key );
252+ cbor_item_t * key_copy = cbor_copy (it [i ].key );
252253 if (key_copy == NULL ) {
253254 cbor_decref (& res );
254255 return NULL ;
255256 }
256- cbor_item_t * value_copy = cbor_copy (it [i ].value );
257+ cbor_item_t * value_copy = cbor_copy (it [i ].value );
257258 if (value_copy == NULL ) {
258259 cbor_decref (& res );
259260 cbor_decref (& key_copy );
@@ -272,16 +273,19 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
272273 return res ;
273274 }
274275 case CBOR_TYPE_TAG : {
275- cbor_item_t * item_copy = cbor_copy (cbor_move (cbor_tag_item (item )));
276+ cbor_item_t * item_copy = cbor_copy (cbor_move (cbor_tag_item (item )));
276277 if (item_copy == NULL ) {
277278 return NULL ;
278279 }
279- cbor_item_t * tag = cbor_build_tag (cbor_tag_value (item ), item_copy );
280+ cbor_item_t * tag = cbor_build_tag (cbor_tag_value (item ), item_copy );
280281 cbor_decref (& item_copy );
281282 return tag ;
282283 }
283284 case CBOR_TYPE_FLOAT_CTRL :
284285 return _cbor_copy_float_ctrl (item );
286+ default :
287+ _CBOR_UNREACHABLE ;
288+ return NULL ;
285289 }
286290}
287291
@@ -300,11 +304,11 @@ static int _pow(int b, int ex) {
300304 return res ;
301305}
302306
303- static void _cbor_type_marquee (FILE * out , char * label , int indent ) {
307+ static void _cbor_type_marquee (FILE * out , char * label , int indent ) {
304308 fprintf (out , "%*.*s[%s] " , indent , indent , " " , label );
305309}
306310
307- static void _cbor_nested_describe (cbor_item_t * item , FILE * out , int indent ) {
311+ static void _cbor_nested_describe (cbor_item_t * item , FILE * out , int indent ) {
308312 const int indent_offset = 4 ;
309313 switch (cbor_typeof (item )) {
310314 case CBOR_TYPE_UINT : {
@@ -328,7 +332,7 @@ static void _cbor_nested_describe(cbor_item_t *item, FILE *out, int indent) {
328332 _cbor_nested_describe (cbor_bytestring_chunks_handle (item )[i ], out ,
329333 indent + indent_offset );
330334 } else {
331- const unsigned char * data = cbor_bytestring_handle (item );
335+ const unsigned char * data = cbor_bytestring_handle (item );
332336 fprintf (out , "Definite, Length: %zuB, Data:\n" ,
333337 cbor_bytestring_length (item ));
334338 fprintf (out , "%*s" , indent + indent_offset , " " );
@@ -417,7 +421,7 @@ static void _cbor_nested_describe(cbor_item_t *item, FILE *out, int indent) {
417421 }
418422}
419423
420- void cbor_describe (cbor_item_t * item , FILE * out ) {
424+ void cbor_describe (cbor_item_t * item , FILE * out ) {
421425 _cbor_nested_describe (item , out , 0 );
422426}
423427
0 commit comments