forked from lei.chen/myxce
fix: correct zarray single-pointer convention in build_host_eval_ctx; add num_res guard
This commit is contained in:
parent
907d8d80a3
commit
2e3469c3c5
2 changed files with 11 additions and 10 deletions
|
|
@ -131,6 +131,11 @@ build_host_eval_ctx(const xce_sched_worker_t* w, int num_res)
|
|||
host_eval_ctx_t* ctx = calloc(1, sizeof(*ctx));
|
||||
if (ctx == NULL) return NULL;
|
||||
|
||||
if (num_res <= 0) {
|
||||
free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
double* numvals = calloc(num_res, sizeof(double));
|
||||
const char** strvals = calloc(num_res, sizeof(char*));
|
||||
if (numvals == NULL || strvals == NULL) {
|
||||
|
|
@ -141,9 +146,8 @@ build_host_eval_ctx(const xce_sched_worker_t* w, int num_res)
|
|||
}
|
||||
|
||||
for (int i = 0; i < num_res; i++) {
|
||||
xce_val_t** slot = (xce_val_t**)zarray_get((zarray_t*)&w->resvals, i);
|
||||
if (slot == NULL || *slot == NULL) continue;
|
||||
xce_val_t* v = *slot;
|
||||
xce_val_t* v = (xce_val_t*)zarray_get((zarray_t*)&w->resvals, i);
|
||||
if (v == NULL) continue;
|
||||
switch (v->which) {
|
||||
case Value_u_fvalue:
|
||||
numvals[i] = (double)v->u.fvalue;
|
||||
|
|
|
|||
|
|
@ -85,12 +85,11 @@ test_build_host_eval_ctx_float(void)
|
|||
|
||||
xce_val_t v;
|
||||
memset(&v, 0, sizeof(v));
|
||||
v.which = 5; /* Value_u_fvalue */
|
||||
v.which = Value_u_fvalue;
|
||||
v.u.fvalue = 4.0;
|
||||
|
||||
/* zarray stores xce_val_t* items; pass pointer-to-pointer */
|
||||
xce_val_t* vp = &v;
|
||||
zarray_put(&w.resvals, 2, &vp);
|
||||
/* store xce_val_t* directly, matching production put_resvals behavior */
|
||||
zarray_put(&w.resvals, 2, &v);
|
||||
|
||||
host_eval_ctx_t* ctx = build_host_eval_ctx(&w, 3);
|
||||
TEST_ASSERT_NOT_NULL(ctx);
|
||||
|
|
@ -99,9 +98,7 @@ test_build_host_eval_ctx_float(void)
|
|||
TEST_ASSERT_NULL(ctx->strvals[2]);
|
||||
TEST_ASSERT_EQUAL_INT(3, ctx->num_res);
|
||||
|
||||
free((void*)ctx->numvals);
|
||||
free((void*)ctx->strvals);
|
||||
free(ctx);
|
||||
free_host_eval_ctx(ctx);
|
||||
zarray_fini(&w.resvals);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue