btstack_tlv_posix: avoid fwrite with len = 0 and ptr = NULL

This commit is contained in:
Matthias Ringwald 2019-05-16 15:10:55 +02:00
parent eab6959f71
commit 2d3020e7ab

View File

@ -75,9 +75,11 @@ static int btstack_tlv_posix_append_tag(btstack_tlv_posix_t * self, uint32_t tag
big_endian_store_32(header, 4, data_size);
size_t written_header = fwrite(header, 1, sizeof(header), self->file);
if (written_header != sizeof(header)) return 1;
size_t written_value = fwrite(data, 1, data_size, self->file);
if (written_value != data_size) return 1;
fflush(self->file);
if (data_size > 0) {
size_t written_value = fwrite(data, 1, data_size, self->file);
if (written_value != data_size) return 1;
}
fflush(self->file);
return 1;
}