fabiocfabini commented on code in PR #3732:
URL: https://github.com/apache/avro/pull/3732#discussion_r3207421437
##########
lang/c/src/encoding_binary.c:
##########
@@ -136,8 +136,8 @@ static int read_bytes(avro_reader_t reader, char **bytes,
int64_t * len)
avro_set_error("Cannot allocate buffer for bytes value");
return ENOMEM;
}
- AVRO_READ(reader, *bytes, *len);
(*bytes)[*len] = '\0';
+ AVRO_READ_OR_FREE(reader, *bytes, *len);
Review Comment:
Thank you for the feedback!
`read_bytes()` and `read_string()` are not part of the user API. They are
called by the `avro_value_read()` which is part of the user API.
The stack frame goes like this: _user frame_ -> `avro_value_read()` frame ->
`avro_read()` frame.
`avro_read` dispatches to the proper read procedure depending on the inner
type of the value being constructed. In the dispatch branches that relate to
`avro_bytes()` and `avro_read()` these calls are wrapped inside a
`check_prefix` (see
[read_bytes](https://github.com/apache/avro/blob/main/lang/c/src/value-read.c#L241-L247)
and
[read_string](https://github.com/apache/avro/blob/main/lang/c/src/value-read.c#L307-L320)
relevant source code lines) macro which short circuits in case of bad return
code. On error, the pointers are not used.
So to answer your questions:
**_what should callers expect to find in the `*bytes` or `*s` pointer?_**:
Given that the pointers are not used, they don't need to be in any specific
state. However, assigning the pointers to `NULL` is standard.
**_Will it be NULL because of macro expansion or not?_**: Yes, in case of
error the pointers are freed and set to `NULL`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]