[ 
https://issues.apache.org/jira/browse/AVRO-741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12985631#action_12985631
 ] 

Bruce Mitchener commented on AVRO-741:
--------------------------------------

That's due to this change:


diff --git a/lang/c/src/encoding_binary.c b/lang/c/src/encoding_binary.c
index 819711e..b464f96 100644
--- a/lang/c/src/encoding_binary.c
+++ b/lang/c/src/encoding_binary.c
@@ -16,6 +16,7 @@
  */
 
 #include "avro_private.h"
+#include "allocation.h"
 #include "encoding.h"
 #include <stdlib.h>
 #include <limits.h>
@@ -126,11 +127,10 @@ static int read_bytes(avro_reader_t reader, char **bytes, 
int64_t * len)
        if (rval) {
                return rval;
        }
-       *bytes = malloc(*len + 1);
+       *bytes = avro_malloc(*len);
        if (!*bytes) {
                return ENOMEM;
        }
-       (*bytes)[*len] = '\0';
        AVRO_READ(reader, *bytes, *len);
        return 0;
 }
@@ -169,10 +169,21 @@ size_bytes(avro_writer_t writer, const char *bytes, const 
int64_t len)
        return size_long(writer, len) + len;
 }
 
-static int read_string(avro_reader_t reader, char **s)
+static int read_string(avro_reader_t reader, char **s, int64_t *len)
 {
-       int64_t len;
-       return read_bytes(reader, s, &len);
+       int64_t  str_len;
+       int rval = read_long(reader, &str_len);
+       if (rval) {
+               return rval;
+       }
+       *len = str_len + 1;
+       *s = avro_malloc(*len);
+       if (!*s) {
+               return ENOMEM;
+       }
+       (*s)[str_len] = '\0';
+       AVRO_READ(reader, *s, str_len);
+       return 0;
 }
 
 static int skip_string(avro_reader_t reader)

Why is that the right thing to do?

There's nothing in the spec that says we can't zero-terminate the byte array 
... there's also nothing about strings being null terminated, but we do that in 
C.

I'm inclined to just revert that part of that change so that byte arrays that 
are read from a file are null terminated once again.


> C: examples/quickstep segfaults
> -------------------------------
>
>                 Key: AVRO-741
>                 URL: https://issues.apache.org/jira/browse/AVRO-741
>             Project: Avro
>          Issue Type: Bug
>          Components: c
>            Reporter: Doug Cutting
>            Priority: Blocker
>             Fix For: 1.5.0
>
>
> On ubuntu 10.10 32-bit, 'cd lang/c; configure ; make check' currently fails.  
> The failure is when running examples/quickstep:
> {code}
> make[2]: Entering directory `/home/cutting/src/avro/trunk/lang/c/examples'
> Successfully added Hicks, Dante id=1
> Successfully added Graves, Randal id=2
> Successfully added Loughran, Veronica id=3
> Successfully added Bree, Caitlin id=4
> Successfully added Silent, Bob id=5
> Successfully added ???, Jay id=6
> Now let's read all the records back out
> Error printing person
> FAIL: quickstop
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to