From 4d4f226a83dd15a3df165429fe6b3f17650a3103 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 18 Nov 2023 17:17:04 +0100 Subject: [PATCH] Prevent crash, when vector is defined, but still empty. --- src/frontend/com_measure2.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/frontend/com_measure2.c b/src/frontend/com_measure2.c index 5b947eacf..7033abbec 100644 --- a/src/frontend/com_measure2.c +++ b/src/frontend/com_measure2.c @@ -400,6 +400,11 @@ com_measure_when( return MEASUREMENT_FAILURE; } + if (dScale->v_realdata ==NULL && dScale->v_compdata == NULL) { + fprintf(cp_err, "Error: scale vector time, frequency or dc has no data.\n"); + return MEASUREMENT_FAILURE; + } + prevValue = 0.; prevValue2 = 0.; prevScaleValue = 0.; @@ -658,6 +663,11 @@ measure_at( return MEASUREMENT_FAILURE; } + if (dScale->v_realdata == NULL && dScale->v_compdata == NULL) { + fprintf(cp_err, "Error: scale vector time, frequency or dc has no data.\n"); + return MEASUREMENT_FAILURE; + } + /* ----------------------------------------------------------------- * Take the string tests outside of the loop for speed. * ----------------------------------------------------------------- */ @@ -768,7 +778,12 @@ measure_minMaxAvg( } if (dScale == NULL) { - fprintf(cp_err, "Error: no such vector as time, frquency or v-sweep.\n"); + fprintf(cp_err, "Error: no such vector as time, frequency or v-sweep.\n"); + return MEASUREMENT_FAILURE; + } + + if (dScale->v_realdata == NULL && dScale->v_compdata == NULL) { + fprintf(cp_err, "Error: scale vector time, frequency or v-sweep has no data.\n"); return MEASUREMENT_FAILURE; } @@ -944,7 +959,12 @@ measure_rms_integral( } if (xScale == NULL) { - fprintf(cp_err, "Error: no such vector as time.\n"); + fprintf(cp_err, "Error: no such vector as time, frequency or v-sweep.\n"); + return MEASUREMENT_FAILURE; + } + + if (xScale->v_realdata == NULL && xScale->v_compdata == NULL) { + fprintf(cp_err, "Error: scale vector time, frequency or v-sweep has no data.\n"); return MEASUREMENT_FAILURE; }