diff options
author | Alan Antonuk <alan.antonuk@gmail.com> | 2015-11-10 22:52:15 -0800 |
---|---|---|
committer | Alan Antonuk <alan.antonuk@gmail.com> | 2015-11-10 22:52:15 -0800 |
commit | 2a12d8cc3f94e565a1adcdb308909cb232f08706 (patch) | |
tree | f545c5da7d9a289e62f62fd4d9431eab5c22049d | |
parent | 1b9c0adbd722d849ceb451fdb4ca02e96630e2ea (diff) | |
download | rabbitmq-c-scan-build-fixes.tar.gz |
Lib: don't pass NULL to memcpy in amqp_table.cscan-build-fixes
Issue surfaced by clang static-analyzer v3.5.
-rw-r--r-- | librabbitmq/amqp_table.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/librabbitmq/amqp_table.c b/librabbitmq/amqp_table.c index 058b955..f05593d 100644 --- a/librabbitmq/amqp_table.c +++ b/librabbitmq/amqp_table.c @@ -106,14 +106,18 @@ static int amqp_decode_array(amqp_bytes_t encoded, output->num_entries = num_entries; output->entries = amqp_pool_alloc(pool, num_entries * sizeof(amqp_field_value_t)); - res = AMQP_STATUS_NO_MEMORY; /* NULL is legitimate if we requested a zero-length block. */ - if (output->entries == NULL && num_entries > 0) { + if (output->entries == NULL) { + if (num_entries == 0) { + res = AMQP_STATUS_OK; + } else { + res = AMQP_STATUS_NO_MEMORY; + } goto out; } memcpy(output->entries, entries, num_entries * sizeof(amqp_field_value_t)); - res = 0; + res = AMQP_STATUS_OK; out: free(entries); @@ -178,9 +182,13 @@ int amqp_decode_table(amqp_bytes_t encoded, output->num_entries = num_entries; output->entries = amqp_pool_alloc(pool, num_entries * sizeof(amqp_table_entry_t)); - res = AMQP_STATUS_NO_MEMORY; /* NULL is legitimate if we requested a zero-length block. */ - if (output->entries == NULL && num_entries > 0) { + if (output->entries == NULL) { + if (num_entries == 0) { + res = AMQP_STATUS_OK; + } else { + res = AMQP_STATUS_NO_MEMORY; + } goto out; } |