From 2e3469c3c5a4b682860d3abfac39646822c83f82 Mon Sep 17 00:00:00 2001 From: Rongsong Shen Date: Thu, 30 Apr 2026 04:58:28 +0000 Subject: [PATCH] fix: correct zarray single-pointer convention in build_host_eval_ctx; add num_res guard --- src/scheduler/src/resource.c | 10 +++++++--- src/scheduler/testsuite/test.c | 11 ++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/scheduler/src/resource.c b/src/scheduler/src/resource.c index 35bf857..1ebdbf7 100644 --- a/src/scheduler/src/resource.c +++ b/src/scheduler/src/resource.c @@ -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; diff --git a/src/scheduler/testsuite/test.c b/src/scheduler/testsuite/test.c index ef009b2..d8b7313 100644 --- a/src/scheduler/testsuite/test.c +++ b/src/scheduler/testsuite/test.c @@ -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); }