commit 3b38b840aa892559966075831c33ae15f8d9d74e
parent a3dc11c379fbd6469652788cd8292423935bed55
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Sat, 7 Feb 2026 08:40:09 +0100
fix(arrays): align allocation helper allocation semantics
Diffstat:
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/arrays.c b/arrays.c
@@ -100,14 +100,11 @@ spacing(const double *x, const int n)
double *
zeros(const int n)
{
- int i;
double *x;
check_magnitude(__func__, 1, n);
if (!(x = calloc(n, sizeof(double))))
err(1, "%s: x calloc", __func__);
- for (i = 0; i < n; ++i)
- x[i] = 0.0;
return x;
}
@@ -120,8 +117,8 @@ ones(const int n)
double *x;
check_magnitude(__func__, 1, n);
- if (!(x = calloc(n, sizeof(double))))
- err(1, "%s: x calloc", __func__);
+ if (!(x = malloc(n * sizeof(double))))
+ err(1, "%s: x malloc", __func__);
for (i = 0; i < n; ++i)
x[i] = 1.0;
@@ -136,8 +133,8 @@ initval(const double value, const int n)
double *x;
check_magnitude(__func__, 1, n);
- if (!(x = calloc(n, sizeof(double))))
- err(1, "%s: x calloc", __func__);
+ if (!(x = malloc(n * sizeof(double))))
+ err(1, "%s: x malloc", __func__);
for (i = 0; i < n; ++i)
x[i] = value;
@@ -152,8 +149,8 @@ empty(const int n)
check_magnitude(__func__, 1, n);
- if (!(out = calloc(n, sizeof(double))))
- err(1, "%s: calloc", __func__);
+ if (!(out = malloc(n * sizeof(double))))
+ err(1, "%s: malloc", __func__);
return out;
}