summaryrefslogtreecommitdiff
path: root/p11-kit
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2017-05-29 17:14:14 +0200
committerDaiki Ueno <ueno@gnu.org>2017-05-29 17:28:51 +0200
commit3e65d8a23b1f0e1a4d132cf04fdbc9d588cbe02f (patch)
treeb91acc4d94386b4aa1651b7888c9ad934e60a9c6 /p11-kit
parent350bd148d3181c564eeb884dadc37aaed7d3fb9b (diff)
proxy: Don't call realloc() with size 0
Spotted by clang-analyzer.
Diffstat (limited to 'p11-kit')
-rw-r--r--p11-kit/proxy.c20
1 files changed, 11 insertions, 9 deletions
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);