Add a test for cbor_serialize_tag  edgecases
@@ -402,6 +402,22 @@ static void test_serialize_tags(void **_CBOR_UNUSED(_state)) {
cbor_decref(&one);
}
+static void test_serialize_tags_no_space(void **_CBOR_UNUSED(_state)) {
+ cbor_item_t *item = cbor_new_tag(21);
+ cbor_item_t *one = cbor_build_uint8(1);
+ cbor_tag_set_item(item, one);
+ assert_int_equal(cbor_serialized_size(item), 2);
+
+ // Not enough space for the leading byte
+ assert_int_equal(cbor_serialize(item, buffer, 0), 0);
+
+ // Not enough space for the item
+ assert_int_equal(cbor_serialize(item, buffer, 1), 0);
+
+ cbor_decref(&item);
+ cbor_decref(&one);
+}
+
static void test_serialize_half(void **_CBOR_UNUSED(_state)) {
cbor_item_t *item = cbor_new_float2();
cbor_set_float2(item, NAN);
@@ -544,6 +560,7 @@ int main(void) {
cmocka_unit_test(test_serialize_indefinite_map),
cmocka_unit_test(test_serialize_map_no_space),
cmocka_unit_test(test_serialize_tags),
+ cmocka_unit_test(test_serialize_tags_no_space),
cmocka_unit_test(test_serialize_half),
cmocka_unit_test(test_serialize_single),
cmocka_unit_test(test_serialize_double),
