From 0221a0aa2523f3878534fd856bb4d751bb9c4a9e Mon Sep 17 00:00:00 2001 From: Yingjie Wang Date: Tue, 11 Nov 2025 02:01:26 -0500 Subject: [PATCH] fix: pass **x instead This is because when I pass *x then it's just a copy. --- src/init.c | 14 +++++++------- src/init.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/init.c b/src/init.c index bfdfd90..55ac059 100644 --- a/src/init.c +++ b/src/init.c @@ -133,9 +133,9 @@ static void refine_interval(double xl, double xr, double yl, double yr, double r return ; } -int init(double bmax, double rela_err_limit, int *size, double *x, double *y){ - if (x) free(x); - if (y) free(y); +int init(double bmax, double rela_err_limit, int *size, double **x, double **y){ + if (*x) free(*x); + if (*y) free(*y); SampleData sample; sample.capacity = 1; sample.size=1; @@ -155,12 +155,12 @@ int init(double bmax, double rela_err_limit, int *size, double *x, double *y){ //printf("Total sample points capacity: %d\n", sample.capacity); //printf("Total sample points number: %d\n", sample.size); *size = sample.size; - x = malloc(sizeof(double) * sample.size); - y = malloc(sizeof(double) * sample.size); + *x = malloc(sizeof(double) * sample.size); + *y = malloc(sizeof(double) * sample.size); for (int i = 0; i < sample.size; i++) { //printf("%.16g %.16g\n", sample.x[i], sample.y[i]); - x[i] = sample.x[i]; - y[i] = sample.y[i]; + (*x)[i] = sample.x[i]; + (*y)[i] = sample.y[i]; } free(sample.x); diff --git a/src/init.h b/src/init.h index 6863160..e6ee675 100644 --- a/src/init.h +++ b/src/init.h @@ -1,2 +1,2 @@ double chi(double b); -int init(double bmax, double rela_err_limit, int *size, double *x, double *y); +int init(double bmax, double rela_err_limit, int *size, double **x, double **y);