diff --git a/clients/common/nm-client-utils.c b/clients/common/nm-client-utils.c index d5f8b2a336..a15a10b3bc 100644 --- a/clients/common/nm-client-utils.c +++ b/clients/common/nm-client-utils.c @@ -21,30 +21,6 @@ #include "nm-client-utils.h" -/* - * Convert string to signed integer. - * If required, the resulting number is checked to be in the range. - */ -static gboolean -nmc_string_to_int_base (const char *str, - int base, - gboolean range_check, - long int min, - long int max, - long int *value) -{ - char *end; - long int tmp; - - errno = 0; - tmp = strtol (str, &end, base); - if (errno || *end != '\0' || (range_check && (tmp < min || tmp > max))) { - return FALSE; - } - *value = tmp; - return TRUE; -} - /* * Convert string to unsigned integer. * If required, the resulting number is checked to be in the range. @@ -69,16 +45,6 @@ nmc_string_to_uint_base (const char *str, return TRUE; } -gboolean -nmc_string_to_int (const char *str, - gboolean range_check, - long int min, - long int max, - long int *value) -{ - return nmc_string_to_int_base (str, 10, range_check, min, max, value); -} - gboolean nmc_string_to_uint (const char *str, gboolean range_check, diff --git a/clients/common/nm-client-utils.h b/clients/common/nm-client-utils.h index 46479c7e32..aea29e6360 100644 --- a/clients/common/nm-client-utils.h +++ b/clients/common/nm-client-utils.h @@ -33,11 +33,6 @@ const char *nmc_string_is_valid (const char *input, const char **allowed, GError char **nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens); -gboolean nmc_string_to_int (const char *str, - gboolean range_check, - long int min, - long int max, - long int *value); gboolean nmc_string_to_uint (const char *str, gboolean range_check, unsigned long int min, diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 8312fb429f..88f363d7e6 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -791,54 +791,54 @@ _set_fcn_gobject_bool (ARGS_SET_FCN) static gboolean _set_fcn_gobject_trilean (ARGS_SET_FCN) { - long int val_int; + const int INVALID = G_MININT; + int v; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_int (value, TRUE, -1, 1, &val_int)) { + v = _nm_utils_ascii_str_to_int64 (value, 10, -1, 1, INVALID); + if (v == INVALID) { g_set_error (error, 1, 0, _("'%s' is not a valid value; use -1, 0 or 1"), value); return FALSE; } - - g_object_set (setting, property_info->property_name, val_int, NULL); + g_object_set (setting, property_info->property_name, v, NULL); return TRUE; } static gboolean _set_fcn_gobject_int (ARGS_SET_FCN) { - long int val_int; + const gint64 INVALID = G_MININT64; + gint64 v; - if (!nmc_string_to_int (value, TRUE, G_MININT, G_MAXINT, &val_int)) { + v = _nm_utils_ascii_str_to_int64 (value, 10, G_MININT, G_MAXINT, INVALID); + if (v == INVALID) { g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), value); return FALSE; } /* Validate the number according to the property spec */ - if (!validate_int (setting, property_info->property_name, (gint) val_int, error)) + if (!validate_int (setting, property_info->property_name, v, error)) return FALSE; - g_object_set (setting, property_info->property_name, (gint) val_int, NULL); + g_object_set (setting, property_info->property_name, (int) v, NULL); return TRUE; } static gboolean _set_fcn_gobject_int64 (ARGS_SET_FCN) { - long val_int; + gint64 v; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_int (value, FALSE, 0, 0, &val_int)) { + v = _nm_utils_ascii_str_to_int64 (value, 10, G_MININT64, G_MAXINT64, 0); + if (errno) { g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), value); return FALSE; } /* Validate the number according to the property spec */ - if (!validate_int64 (setting, property_info->property_name, (gint64) val_int, error)) + if (!validate_int64 (setting, property_info->property_name, v, error)) return FALSE; - g_object_set (setting, property_info->property_name, (gint64) val_int, NULL); + g_object_set (setting, property_info->property_name, v, NULL); return TRUE; } @@ -2717,20 +2717,19 @@ _set_fcn_dcb_flags (ARGS_SET_FCN) static gboolean _set_fcn_dcb_priority (ARGS_SET_FCN) { - long int priority = 0; + const int INVALID = G_MININT; + int v; - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!nmc_string_to_int (value, FALSE, -1, 7, &priority)) { + v = _nm_utils_ascii_str_to_int64 (value, 10, -1, 7, INVALID); + if (v == INVALID) { g_set_error (error, 1, 0, _("'%s' is not a DCB app priority"), value); return FALSE; } - /* Validate the number according to the property spec */ - if (!validate_int (setting, property_info->property_name, (gint) priority, error)) + if (!validate_int (setting, property_info->property_name, v, error)) return FALSE; - g_object_set (setting, property_info->property_name, (gint) priority, NULL); + g_object_set (setting, property_info->property_name, v, NULL); return TRUE; }