Skip to content

Commit 8b54c23

Browse files
committed
ps_matched: xcalloc() takes nmemb and then element size
Even though multiplication is commutative, the order of arguments should be xcalloc(nmemb, size). ps_matched is an array of 1-byte element whose size is the same as the number of pathspec elements. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8545932 commit 8b54c23

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static int checkout_paths(const struct checkout_opts *opts,
280280
if (opts->source_tree)
281281
read_tree_some(opts->source_tree, &opts->pathspec);
282282

283-
ps_matched = xcalloc(1, opts->pathspec.nr);
283+
ps_matched = xcalloc(opts->pathspec.nr, 1);
284284

285285
/*
286286
* Make sure all pathspecs participated in locating the paths

builtin/ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
516516

517517
/* Treat unmatching pathspec elements as errors */
518518
if (pathspec.nr && error_unmatch)
519-
ps_matched = xcalloc(1, pathspec.nr);
519+
ps_matched = xcalloc(pathspec.nr, 1);
520520

521521
if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given)
522522
die("ls-files --ignored needs some exclude pattern");

0 commit comments

Comments
 (0)