Skip to content

Commit

Permalink
calloc
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Oct 25, 2024
1 parent cea8db4 commit 4d4ee6c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/algs/cdirect/cdirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ nlopt_result cdirect(int n, nlopt_func f, void *f_data,
int i;

d.f = f; d.f_data = f_data; d.lb = lb; d.ub = ub;
d.x = (double *) malloc(sizeof(double) * n * (stop->xtol_abs ? 4 : 3));
d.x = (double *) calloc(n * (stop->xtol_abs ? 4 : 3), sizeof(double));
if (!d.x) return NLOPT_OUT_OF_MEMORY;

for (i = 0; i < n; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/algs/cdirect/hybrid.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ nlopt_result cdirect_hybrid(int n, nlopt_func f, void *f_data,
int i;

d.f = f; d.f_data = f_data; d.lb = lb; d.ub = ub;
d.x = (double *) malloc(sizeof(double) * n * (stop->xtol_abs ? 4 : 3));
d.x = (double *) calloc(n * (stop->xtol_abs ? 4 : 3), sizeof(double));
if (!d.x) return NLOPT_OUT_OF_MEMORY;

for (i = 0; i < n; ++i) {
Expand Down

0 comments on commit 4d4ee6c

Please sign in to comment.