Skip to content

Commit b1aba1f

Browse files
committed
device: error if R[address] has no value in set_features_from_string
1 parent 28e0cb1 commit b1aba1f

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/arvdevice.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,14 +1224,22 @@ arv_device_set_features_from_string (ArvDevice *device, const char *string, GErr
12241224
ARV_DEVICE_ERROR_INVALID_PARAMETER,
12251225
"Invalid address in %s", key);
12261226
} else {
1227-
int_value = g_ascii_strtoll (value, &end, 0);
1228-
if (end == NULL || end[0] != '\0') {
1227+
if (value == NULL || strlen (value) == 0) {
12291228
g_set_error (&local_error,
12301229
ARV_DEVICE_ERROR,
12311230
ARV_DEVICE_ERROR_INVALID_PARAMETER,
1232-
"Invalid %s value for %s", value, key);
1231+
"Value not found for %s", key);
12331232
} else {
1234-
arv_device_write_register (device, address, int_value, &local_error);
1233+
int_value = g_ascii_strtoll (value, &end, 0);
1234+
if (end == NULL || end[0] != '\0') {
1235+
g_set_error (&local_error,
1236+
ARV_DEVICE_ERROR,
1237+
ARV_DEVICE_ERROR_INVALID_PARAMETER,
1238+
"Invalid %s value for %s", value, key);
1239+
} else {
1240+
arv_device_write_register (device, address, int_value,
1241+
&local_error);
1242+
}
12351243
}
12361244
}
12371245
} else {

tests/fake.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,18 @@ set_features_from_string_test (void)
726726
g_assert (success);
727727
g_assert (error == NULL);
728728

729+
success = arv_device_set_features_from_string (device, "R[0x1f0]", &error);
730+
g_assert (!success);
731+
g_assert (error != NULL);
732+
g_clear_error (&error);
733+
734+
success = arv_device_set_features_from_string (device, "R[0x1f0]=10", &error);
735+
g_assert (success);
736+
g_assert (error == NULL);
737+
int_value = arv_device_get_integer_feature_value (device, "TestRegister", &error);
738+
g_assert (error == NULL);
739+
g_assert_cmpint(int_value, ==, 10);
740+
729741
success = arv_device_set_features_from_string (device, NULL, NULL);
730742
g_assert (success);
731743

0 commit comments

Comments
 (0)