commit d45ffad5d51039b641be20cb7a15bdfd105a783d
parent 55db9d064e592ed010d5e2420f0bb2be2fecfa8f
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Wed, 9 Jul 2025 18:36:45 +0200
Fix: return NULL when volume is not a sensor
The function sphin_volume_get_sensor should accept volumes that are
not sensors. In such cases, the correct behavior is to return NULL as
the sensor and the response status RES_OK — both for consistency with
how surface_sources are handled, and to allow library users to easily
check whether a volume is a sensor via the API.
This was not the case previously, and this commit fixes that behavior.
Diffstat:
3 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/sphin.h b/src/sphin.h
@@ -281,7 +281,7 @@ sphin_volume_get_ka
double* ka);
SPHIN_API res_T
-sphin_volume_get_sensor_volume
+sphin_volume_get_sensor
(struct sphin_volume* volume,
struct sphin_sensor_volume** sensor_volume);
diff --git a/src/sphin_volume.c b/src/sphin_volume.c
@@ -321,13 +321,12 @@ sphin_volume_get_ka
}
res_T
-sphin_volume_get_sensor_volume
+sphin_volume_get_sensor
(struct sphin_volume* volume,
struct sphin_sensor_volume** sensor_volume)
{
if (NULL == volume
- || NULL == sensor_volume
- || NULL == volume->sensor_volume ) {
+ || NULL == sensor_volume ) {
return RES_BAD_ARG;
}
*sensor_volume = volume->sensor_volume;
diff --git a/src/test_sphin_load_volume.c b/src/test_sphin_load_volume.c
@@ -131,10 +131,10 @@ test_volume_api
CHK(sphin_volume_get_ka(volume, NULL) == RES_BAD_ARG);
CHK(sphin_volume_get_ka(volume, &ka) == RES_OK);
CHK(eq_eps(ka, 2.11, 1e-15));
- CHK(sphin_volume_get_sensor_volume(NULL, NULL) == RES_BAD_ARG);
- CHK(sphin_volume_get_sensor_volume(NULL, &sensor_volume) == RES_BAD_ARG);
- CHK(sphin_volume_get_sensor_volume(volume, NULL) == RES_BAD_ARG);
- CHK(sphin_volume_get_sensor_volume(volume, &sensor_volume) == RES_OK);
+ CHK(sphin_volume_get_sensor(NULL, NULL) == RES_BAD_ARG);
+ CHK(sphin_volume_get_sensor(NULL, &sensor_volume) == RES_BAD_ARG);
+ CHK(sphin_volume_get_sensor(volume, NULL) == RES_BAD_ARG);
+ CHK(sphin_volume_get_sensor(volume, &sensor_volume) == RES_OK);
CHK(sphin_sensor_volume_get_response_function(NULL, NULL) == RES_BAD_ARG);
CHK(sphin_sensor_volume_get_response_function(NULL, &response_function) == RES_BAD_ARG);
CHK(sphin_sensor_volume_get_response_function(sensor_volume, NULL) == RES_BAD_ARG);
@@ -147,7 +147,7 @@ test_volume_api
CHK(sphin_config_get_volume(config, 1, &volume) == RES_OK);
CHK(sphin_volume_get_ka(volume, &ka) == RES_OK);
CHK(eq_eps(ka, 10, 1e-15));
- CHK(sphin_volume_get_sensor_volume(volume, &sensor_volume) == RES_BAD_ARG); /* Volume has no sensor_volume */
+ CHK(sphin_volume_get_sensor(volume, &sensor_volume) == RES_OK);
/* Test volume 2 */
CHK(sphin_config_get_volume(config, 2, &volume) == RES_OK);