]> granicus.if.org Git - p11-kit/commitdiff
proxy: Don't call realloc() with size 0
authorDaiki Ueno <dueno@redhat.com>
Mon, 29 May 2017 15:14:14 +0000 (17:14 +0200)
committerDaiki Ueno <ueno@gnu.org>
Mon, 29 May 2017 15:28:51 +0000 (17:28 +0200)
Spotted by clang-analyzer.

p11-kit/proxy.c

index 6f91fa446f29772bdd9af0d28f1a247a213e12d8..8c437a0f9837a0483dd8d7c73a44f7ef24780d1e 100644 (file)
@@ -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);