From 3e65d8a23b1f0e1a4d132cf04fdbc9d588cbe02f Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Mon, 29 May 2017 17:14:14 +0200 Subject: proxy: Don't call realloc() with size 0 Spotted by clang-analyzer. --- p11-kit/proxy.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'p11-kit') diff --git a/p11-kit/proxy.c b/p11-kit/proxy.c index 6f91fa4..8c437a0 100644 --- a/p11-kit/proxy.c +++ b/p11-kit/proxy.c @@ -287,15 +287,17 @@ proxy_create (Proxy **res) return_val_if_fail (count == 0 || slots != NULL, CKR_GENERAL_ERROR); - py->mappings = realloc (py->mappings, sizeof (Mapping) * (py->n_mappings + count)); - return_val_if_fail (py->mappings != NULL, CKR_HOST_MEMORY); - - /* And now add a mapping for each of those slots */ - for (i = 0; i < count; ++i) { - py->mappings[py->n_mappings].funcs = funcs; - py->mappings[py->n_mappings].wrap_slot = py->n_mappings + MAPPING_OFFSET; - py->mappings[py->n_mappings].real_slot = slots[i]; - ++py->n_mappings; + if (count > 0) { + py->mappings = realloc (py->mappings, sizeof (Mapping) * (py->n_mappings + count)); + return_val_if_fail (py->mappings != NULL, CKR_HOST_MEMORY); + + /* And now add a mapping for each of those slots */ + for (i = 0; i < count; ++i) { + py->mappings[py->n_mappings].funcs = funcs; + py->mappings[py->n_mappings].wrap_slot = py->n_mappings + MAPPING_OFFSET; + py->mappings[py->n_mappings].real_slot = slots[i]; + ++py->n_mappings; + } } free (slots); -- cgit v1.1