]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tdbtorture: Fix CID 1034816: proper calloc usage
authorShachar Sharon <ssharon@redhat.com>
Tue, 19 Aug 2025 09:18:28 +0000 (12:18 +0300)
committerGünther Deschner <gd@samba.org>
Tue, 19 Aug 2025 18:08:01 +0000 (18:08 +0000)
Standard signature is 'calloc(n_elems, elem_size)', where element size
(in particular, when using 'sizeof') comes as 2nd arg. The actual
allocation size does not care for ordering but swapping the order
confuses static-analysis tools like Coverity, as well as naive readers.

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
Reviewed-by: Vinit Agnihotri <vagnihot@redhat.com>
Reviewed-by: Shweta Sodani <ssodani@redhat.com>
Reviewed-by: Rabinarayan Panigrahi <rapanigr@redhat.com>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Günther Deschner <gd@samba.org>
Autobuild-Date(master): Tue Aug 19 18:08:02 UTC 2025 on atb-devel-224

lib/tdb/tools/tdbtorture.c

index 1063f14f4ccb7046b5d3e769ad6c385c4a27ba20..14dc5e7a8d1102b2888ad0cc19823f4f9096bd7e 100644 (file)
@@ -374,12 +374,12 @@ int main(int argc, char * const *argv)
                goto done;
        }
 
-       pids = (pid_t *)calloc(sizeof(pid_t), num_procs);
+       pids = (pid_t *)calloc(num_procs, sizeof(pid_t));
        if (pids == NULL) {
                perror("Unable to allocate memory for pids");
                exit(1);
        }
-       done = (int *)calloc(sizeof(int), num_procs);
+       done = (int *)calloc(num_procs, sizeof(int));
        if (done == NULL) {
                perror("Unable to allocate memory for done");
                exit(1);