float tmp;
char *response;
gchar **ptr, **tokens;
+ size_t token_count;
GArray *response_array;
*scpi_response = NULL;
- response = NULL;
- tokens = NULL;
+ response = NULL;
ret = sr_scpi_get_string(scpi, command, &response);
if (ret != SR_OK && !response)
return ret;
tokens = g_strsplit(response, ",", 0);
- ptr = tokens;
+ token_count = g_strv_length(tokens);
- response_array = g_array_sized_new(TRUE, FALSE, sizeof(float), 256);
+ response_array = g_array_sized_new(TRUE, FALSE,
+ sizeof(float), token_count + 1);
+ ptr = tokens;
while (*ptr) {
- if (sr_atof_ascii(*ptr, &tmp) == SR_OK)
- response_array = g_array_append_val(response_array,
- tmp);
- else
+ ret = sr_atof_ascii(*ptr, &tmp);
+ if (ret != SR_OK) {
ret = SR_ERR_DATA;
-
+ break;
+ }
+ response_array = g_array_append_val(response_array, tmp);
ptr++;
}
g_strfreev(tokens);
int tmp, ret;
char *response;
gchar **ptr, **tokens;
+ size_t token_count;
GArray *response_array;
*scpi_response = NULL;
- response = NULL;
- tokens = NULL;
+ response = NULL;
ret = sr_scpi_get_string(scpi, command, &response);
if (ret != SR_OK && !response)
return ret;
tokens = g_strsplit(response, ",", 0);
- ptr = tokens;
+ token_count = g_strv_length(tokens);
- response_array = g_array_sized_new(TRUE, FALSE, sizeof(uint8_t), 256);
+ response_array = g_array_sized_new(TRUE, FALSE,
+ sizeof(uint8_t), token_count + 1);
+ ptr = tokens;
while (*ptr) {
- if (sr_atoi(*ptr, &tmp) == SR_OK)
- response_array = g_array_append_val(response_array,
- tmp);
- else
+ ret = sr_atoi(*ptr, &tmp);
+ if (ret != SR_OK) {
ret = SR_ERR_DATA;
-
+ break;
+ }
+ response_array = g_array_append_val(response_array, tmp);
ptr++;
}
g_strfreev(tokens);
}
g_free(response);
- hw_info = g_malloc0(sizeof(struct sr_scpi_hw_info));
+ hw_info = g_malloc0(sizeof(*hw_info));
idn_substr = g_strstr_len(tokens[0], -1, "IDN ");
if (idn_substr == NULL)