Skip to content

Commit afaf46b

Browse files
committed
device: error if R[address] has no value in set_features_from_string
1 parent 3ce1fee commit afaf46b

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
@@ -1182,14 +1182,22 @@ arv_device_set_features_from_string (ArvDevice *device, const char *string, GErr
11821182
ARV_DEVICE_ERROR_INVALID_PARAMETER,
11831183
"Invalid address in %s", key);
11841184
} else {
1185-
int_value = g_ascii_strtoll (value, &end, 0);
1186-
if (end == NULL || end[0] != '\0') {
1185+
if (value == NULL || strlen (value) == 0) {
11871186
g_set_error (&local_error,
11881187
ARV_DEVICE_ERROR,
11891188
ARV_DEVICE_ERROR_INVALID_PARAMETER,
1190-
"Invalid %s value for %s", value, key);
1189+
"Value not found for %s", key);
11911190
} else {
1192-
arv_device_write_register (device, address, int_value, &local_error);
1191+
int_value = g_ascii_strtoll (value, &end, 0);
1192+
if (end == NULL || end[0] != '\0') {
1193+
g_set_error (&local_error,
1194+
ARV_DEVICE_ERROR,
1195+
ARV_DEVICE_ERROR_INVALID_PARAMETER,
1196+
"Invalid %s value for %s", value, key);
1197+
} else {
1198+
arv_device_write_register (device, address, int_value,
1199+
&local_error);
1200+
}
11931201
}
11941202
}
11951203
} else {

tests/fake.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,18 @@ set_features_from_string_test (void)
723723
g_assert (success);
724724
g_assert (error == NULL);
725725

726+
success = arv_device_set_features_from_string (device, "R[0x1f0]", &error);
727+
g_assert (!success);
728+
g_assert (error != NULL);
729+
g_clear_error (&error);
730+
731+
success = arv_device_set_features_from_string (device, "R[0x1f0]=10", &error);
732+
g_assert (success);
733+
g_assert (error == NULL);
734+
int_value = arv_device_get_integer_feature_value (device, "TestRegister", &error);
735+
g_assert (error == NULL);
736+
g_assert_cmpint(int_value, ==, 10);
737+
726738
success = arv_device_set_features_from_string (device, NULL, NULL);
727739
g_assert (success);
728740

0 commit comments

Comments
 (0)