From 526e48e459995b3da58b150083da72f9dd7892c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 9 Feb 2017 15:00:19 +0200 Subject: [PATCH] Fix floats being read as doubles The avro floating point numbers were processed as 8 byte values when they are 4 bytes values. --- avro/maxavro_record.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/avro/maxavro_record.c b/avro/maxavro_record.c index 82e05f873..9327bcf69 100644 --- a/avro/maxavro_record.c +++ b/avro/maxavro_record.c @@ -49,9 +49,11 @@ static json_t* read_and_pack_value(MAXAVRO_FILE *file, MAXAVRO_SCHEMA_FIELD *fie case MAXAVRO_TYPE_LONG: { uint64_t val = 0; - maxavro_read_integer(file, &val); - json_int_t jsonint = val; - value = json_pack("I", jsonint); + if (maxavro_read_integer(file, &val)) + { + json_int_t jsonint = val; + value = json_pack("I", jsonint); + } } break; @@ -74,11 +76,23 @@ static json_t* read_and_pack_value(MAXAVRO_FILE *file, MAXAVRO_SCHEMA_FIELD *fie break; case MAXAVRO_TYPE_FLOAT: + { + float f = 0; + if (maxavro_read_float(file, &f)) + { + double d = f; + value = json_pack("f", d); + } + } + + break; case MAXAVRO_TYPE_DOUBLE: { double d = 0; - maxavro_read_double(file, &d); - value = json_pack("f", d); + if (maxavro_read_double(file, &d)) + { + value = json_pack("f", d); + } } break;