martin-g commented on code in PR #3527:
URL: https://github.com/apache/avro/pull/3527#discussion_r2466816018


##########
lang/c/src/value-json.c:
##########
@@ -126,7 +126,7 @@ avro_value_to_json_t(const avro_value_t *value)
                                return NULL;
                        }
 
-                       json_t  *result = json_stringn_nocheck((const char *) 
encoded, encoded_size);
+                       json_t  *result = json_stringn_nocheck((const char *) 
encoded ? encoded : "", encoded_size);

Review Comment:
   There is a similar code for FIXED at 
https://github.com/steven-aerts/avro/blob/89fb9db03478b793be7188c5683c6560c2eff115/lang/c/src/value-json.c#L244
   Does it need the same improvements ?



##########
lang/c/src/value-json.c:
##########
@@ -126,7 +126,7 @@ avro_value_to_json_t(const avro_value_t *value)
                                return NULL;
                        }
 
-                       json_t  *result = json_stringn_nocheck((const char *) 
encoded, encoded_size);
+                       json_t  *result = json_stringn_nocheck((const char *) 
encoded ? encoded : "", encoded_size);

Review Comment:
   ```suggestion
                        json_t  *result = json_stringn_nocheck((const char *) 
encoded ? encoded : "", encoded ? encoded_size : 0);
   ```
   ?



##########
lang/c/src/datum.c:
##########
@@ -156,7 +156,7 @@ static avro_datum_t avro_bytes_private(char *bytes, int64_t 
size,
 avro_datum_t avro_bytes(const char *bytes, int64_t size)
 {
        char *bytes_copy = (char *) avro_malloc(size);
-       if (!bytes_copy) {
+       if (!bytes_copy && size) {

Review Comment:
   IMO the there must be a check for `size == 0` as a first step in this 
function that returns early and avoids any mallocs and memcpys.



##########
lang/c/src/datum.c:
##########
@@ -197,7 +197,7 @@ int avro_bytes_set(avro_datum_t datum, const char *bytes, 
const int64_t size)
 {
        int rval;
        char *bytes_copy = (char *) avro_malloc(size);
-       if (!bytes_copy) {
+       if (!bytes_copy && size) {

Review Comment:
   Same as above



-- 
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]

Reply via email to