99#include "cbor/internal/builder_callbacks.h"
1010#include "cbor/internal/loaders.h"
1111
12- #pragma clang diagnostic push
13- cbor_item_t * cbor_load (cbor_data source , size_t source_size ,
14- struct cbor_load_result * result ) {
12+ cbor_item_t * cbor_load (cbor_data source , size_t source_size ,
13+ struct cbor_load_result * result ) {
1514 /* Context stack */
1615 static struct cbor_callbacks callbacks = {
1716 .uint8 = & cbor_builder_uint8_callback ,
@@ -115,8 +114,8 @@ cbor_item_t *cbor_load(cbor_data source, size_t source_size,
115114 return NULL ;
116115}
117116
118- static cbor_item_t * _cbor_copy_int (cbor_item_t * item , bool negative ) {
119- cbor_item_t * res ;
117+ static cbor_item_t * _cbor_copy_int (cbor_item_t * item , bool negative ) {
118+ cbor_item_t * res = NULL ;
120119 switch (cbor_int_get_width (item )) {
121120 case CBOR_INT_8 :
122121 res = cbor_build_uint8 (cbor_get_uint8 (item ));
@@ -137,8 +136,7 @@ static cbor_item_t *_cbor_copy_int(cbor_item_t *item, bool negative) {
137136 return res ;
138137}
139138
140- static cbor_item_t * _cbor_copy_float_ctrl (cbor_item_t * item ) {
141- // cppcheck-suppress missingReturn
139+ static cbor_item_t * _cbor_copy_float_ctrl (cbor_item_t * item ) {
142140 switch (cbor_float_get_width (item )) {
143141 case CBOR_FLOAT_0 :
144142 return cbor_build_ctrl (cbor_ctrl_value (item ));
@@ -148,11 +146,13 @@ static cbor_item_t *_cbor_copy_float_ctrl(cbor_item_t *item) {
148146 return cbor_build_float4 (cbor_float_get_float4 (item ));
149147 case CBOR_FLOAT_64 :
150148 return cbor_build_float8 (cbor_float_get_float8 (item ));
149+ default :
150+ _CBOR_UNREACHABLE ;
151+ return NULL ;
151152 }
152153}
153154
154- cbor_item_t * cbor_copy (cbor_item_t * item ) {
155- // cppcheck-suppress missingReturn
155+ cbor_item_t * cbor_copy (cbor_item_t * item ) {
156156 switch (cbor_typeof (item )) {
157157 case CBOR_TYPE_UINT :
158158 return _cbor_copy_int (item , false);
@@ -163,13 +163,13 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
163163 return cbor_build_bytestring (cbor_bytestring_handle (item ),
164164 cbor_bytestring_length (item ));
165165 } else {
166- cbor_item_t * res = cbor_new_indefinite_bytestring ();
166+ cbor_item_t * res = cbor_new_indefinite_bytestring ();
167167 if (res == NULL ) {
168168 return NULL ;
169169 }
170170
171171 for (size_t i = 0 ; i < cbor_bytestring_chunk_count (item ); i ++ ) {
172- cbor_item_t * chunk_copy =
172+ cbor_item_t * chunk_copy =
173173 cbor_copy (cbor_bytestring_chunks_handle (item )[i ]);
174174 if (chunk_copy == NULL ) {
175175 cbor_decref (& res );
@@ -186,16 +186,16 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
186186 }
187187 case CBOR_TYPE_STRING :
188188 if (cbor_string_is_definite (item )) {
189- return cbor_build_stringn ((const char * )cbor_string_handle (item ),
189+ return cbor_build_stringn ((const char * )cbor_string_handle (item ),
190190 cbor_string_length (item ));
191191 } else {
192- cbor_item_t * res = cbor_new_indefinite_string ();
192+ cbor_item_t * res = cbor_new_indefinite_string ();
193193 if (res == NULL ) {
194194 return NULL ;
195195 }
196196
197197 for (size_t i = 0 ; i < cbor_string_chunk_count (item ); i ++ ) {
198- cbor_item_t * chunk_copy =
198+ cbor_item_t * chunk_copy =
199199 cbor_copy (cbor_string_chunks_handle (item )[i ]);
200200 if (chunk_copy == NULL ) {
201201 cbor_decref (& res );
@@ -211,7 +211,7 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
211211 return res ;
212212 }
213213 case CBOR_TYPE_ARRAY : {
214- cbor_item_t * res ;
214+ cbor_item_t * res ;
215215 if (cbor_array_is_definite (item )) {
216216 res = cbor_new_definite_array (cbor_array_size (item ));
217217 } else {
@@ -222,7 +222,7 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
222222 }
223223
224224 for (size_t i = 0 ; i < cbor_array_size (item ); i ++ ) {
225- 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 )));
226226 if (entry_copy == NULL ) {
227227 cbor_decref (& res );
228228 return NULL ;
@@ -237,7 +237,7 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
237237 return res ;
238238 }
239239 case CBOR_TYPE_MAP : {
240- cbor_item_t * res ;
240+ cbor_item_t * res ;
241241 if (cbor_map_is_definite (item )) {
242242 res = cbor_new_definite_map (cbor_map_size (item ));
243243 } else {
@@ -247,14 +247,14 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
247247 return NULL ;
248248 }
249249
250- struct cbor_pair * it = cbor_map_handle (item );
250+ struct cbor_pair * it = cbor_map_handle (item );
251251 for (size_t i = 0 ; i < cbor_map_size (item ); i ++ ) {
252- cbor_item_t * key_copy = cbor_copy (it [i ].key );
252+ cbor_item_t * key_copy = cbor_copy (it [i ].key );
253253 if (key_copy == NULL ) {
254254 cbor_decref (& res );
255255 return NULL ;
256256 }
257- cbor_item_t * value_copy = cbor_copy (it [i ].value );
257+ cbor_item_t * value_copy = cbor_copy (it [i ].value );
258258 if (value_copy == NULL ) {
259259 cbor_decref (& res );
260260 cbor_decref (& key_copy );
@@ -273,16 +273,19 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
273273 return res ;
274274 }
275275 case CBOR_TYPE_TAG : {
276- 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 )));
277277 if (item_copy == NULL ) {
278278 return NULL ;
279279 }
280- 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 );
281281 cbor_decref (& item_copy );
282282 return tag ;
283283 }
284284 case CBOR_TYPE_FLOAT_CTRL :
285285 return _cbor_copy_float_ctrl (item );
286+ default :
287+ _CBOR_UNREACHABLE ;
288+ return NULL ;
286289 }
287290}
288291
@@ -301,11 +304,11 @@ static int _pow(int b, int ex) {
301304 return res ;
302305}
303306
304- static void _cbor_type_marquee (FILE * out , char * label , int indent ) {
307+ static void _cbor_type_marquee (FILE * out , char * label , int indent ) {
305308 fprintf (out , "%*.*s[%s] " , indent , indent , " " , label );
306309}
307310
308- 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 ) {
309312 const int indent_offset = 4 ;
310313 switch (cbor_typeof (item )) {
311314 case CBOR_TYPE_UINT : {
@@ -329,7 +332,7 @@ static void _cbor_nested_describe(cbor_item_t *item, FILE *out, int indent) {
329332 _cbor_nested_describe (cbor_bytestring_chunks_handle (item )[i ], out ,
330333 indent + indent_offset );
331334 } else {
332- const unsigned char * data = cbor_bytestring_handle (item );
335+ const unsigned char * data = cbor_bytestring_handle (item );
333336 fprintf (out , "Definite, Length: %zuB, Data:\n" ,
334337 cbor_bytestring_length (item ));
335338 fprintf (out , "%*s" , indent + indent_offset , " " );
@@ -418,7 +421,7 @@ static void _cbor_nested_describe(cbor_item_t *item, FILE *out, int indent) {
418421 }
419422}
420423
421- void cbor_describe (cbor_item_t * item , FILE * out ) {
424+ void cbor_describe (cbor_item_t * item , FILE * out ) {
422425 _cbor_nested_describe (item , out , 0 );
423426}
424427
0 commit comments