@@ -40,18 +40,20 @@ test_allocator(void *ud, void *ptr, size_t osize, size_t nsize)
4040 AVRO_UNUSED (osize );
4141
4242 if (nsize == 0 ) {
43- size_t * size = ((size_t * ) ptr ) - 1 ;
44- if (osize != * size ) {
45- fprintf (stderr ,
46- "Error freeing %p:\n"
47- "Size passed to avro_free (%" PRIsz ") "
48- "doesn't match size passed to "
49- "avro_malloc (%" PRIsz ")\n" ,
50- ptr , osize , * size );
51- abort ();
52- //exit(EXIT_FAILURE);
43+ if (ptr ) {
44+ size_t * size = ((size_t * ) ptr ) - 1 ;
45+ if (osize != * size ) {
46+ fprintf (stderr ,
47+ "Error freeing %p:\n"
48+ "Size passed to avro_free (%" PRIsz ") "
49+ "doesn't match size passed to "
50+ "avro_malloc (%" PRIsz ")\n" ,
51+ ptr , osize , * size );
52+ abort ();
53+ //exit(EXIT_FAILURE);
54+ }
55+ free (size );
5356 }
54- free (size );
5557 return NULL ;
5658 } else {
5759 size_t real_size = nsize + sizeof (size_t );
@@ -214,6 +216,34 @@ static int test_bytes(void)
214216 return 0 ;
215217}
216218
219+ static int test_empty_bytes (void )
220+ {
221+ char bytes [] = { };
222+ avro_schema_t writer_schema = avro_schema_bytes ();
223+ avro_datum_t datum ;
224+ avro_datum_t expected_datum ;
225+
226+ datum = avro_givebytes (bytes , sizeof (bytes ), NULL );
227+ write_read_check (writer_schema , datum , NULL , NULL , "bytes" );
228+ test_json (datum , "\"\"" );
229+ avro_datum_decref (datum );
230+ avro_schema_decref (writer_schema );
231+
232+ datum = avro_givebytes (NULL , 0 , NULL );
233+ avro_givebytes_set (datum , bytes , sizeof (bytes ), NULL );
234+ expected_datum = avro_givebytes (bytes , sizeof (bytes ), NULL );
235+ if (!avro_datum_equal (datum , expected_datum )) {
236+ fprintf (stderr ,
237+ "Expected equal bytes instances.\n" );
238+ exit (EXIT_FAILURE );
239+ }
240+ avro_datum_decref (datum );
241+ avro_datum_decref (expected_datum );
242+
243+ avro_schema_decref (writer_schema );
244+ return 0 ;
245+ }
246+
217247static int test_int32 (void )
218248{
219249 int i ;
@@ -657,6 +687,7 @@ int main(void)
657687 {
658688 "string" , test_string }, {
659689 "bytes" , test_bytes }, {
690+ "empty_bytes" , test_empty_bytes }, {
660691 "int" , test_int32 }, {
661692 "long" , test_int64 }, {
662693 "float" , test_float }, {
0 commit comments