diff options
author | Thomas Haller <thaller@redhat.com> | 2017-10-04 11:16:36 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-10-04 11:34:51 +0200 |
commit | 29e9b567f0938fd202a433e7098092f0a39723ed (patch) | |
tree | fb250f6e2feec25c6d2690b728b649ec767657c9 | |
parent | 72c28cb6bcc26e6a63083e4d92f8f66ee5c121e4 (diff) | |
download | NetworkManager-29e9b567f0938fd202a433e7098092f0a39723ed.tar.gz |
keyfile: cleanup error argument for read_field()
Rename @error to @out_err_str, because @error is usually used for GError
output arguments.
Also, make the string variables "const char *".
Use nm_assert() in read_field(), because it is a static function
with only four call sites. It's easily verified that the assertion
holds, so no need for a run-time check in production builds.
-rw-r--r-- | libnm-core/nm-keyfile-reader.c | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/libnm-core/nm-keyfile-reader.c b/libnm-core/nm-keyfile-reader.c index 15a0e406fa..5934c833ba 100644 --- a/libnm-core/nm-keyfile-reader.c +++ b/libnm-core/nm-keyfile-reader.c @@ -249,17 +249,17 @@ build_route (KeyfileReaderInfo *info, * When @current target is %NULL, gracefully fail returning %NULL while * leaving the @current target %NULL end setting @error to %NULL; */ -static char * -read_field (char **current, char **error, const char *characters, const char *delimiters) +static const char * +read_field (char **current, const char **out_err_str, const char *characters, const char *delimiters) { - char *start; + const char *start; - g_return_val_if_fail (current, NULL); - g_return_val_if_fail (error, NULL); - g_return_val_if_fail (characters, NULL); - g_return_val_if_fail (delimiters, NULL); + nm_assert (current); + nm_assert (out_err_str); + nm_assert (characters); + nm_assert (delimiters); - *error = NULL; + *out_err_str = NULL; if (!*current) { /* graceful failure, leave '*current' NULL */ @@ -282,8 +282,8 @@ read_field (char **current, char **error, const char *characters, const char *de return start; } else { /* error, bad character */ - *error = *current; - *current = start; + *out_err_str = *current; + *current = (char *) start; return NULL; } else { @@ -332,42 +332,50 @@ read_one_ip_address_or_route (KeyfileReaderInfo *info, char **out_gateway, NMSetting *setting) { - guint32 plen = G_MAXUINT32; + guint plen; gpointer result; - char *address_str, *plen_str, *gateway_str, *metric_str, *current, *error; - gs_free char *value = NULL, *value_orig = NULL; + const char *address_str; + const char *plen_str; + const char *gateway_str; + const char *metric_str; + const char *err_str = NULL; + char *current; + gs_free char *value = NULL; + gs_free char *value_orig = NULL; #define VALUE_ORIG() (value_orig ? value_orig : (value_orig = nm_keyfile_plugin_kf_get_string (info->keyfile, setting_name, key_name, NULL))) - current = value = nm_keyfile_plugin_kf_get_string (info->keyfile, setting_name, key_name, NULL); + value = nm_keyfile_plugin_kf_get_string (info->keyfile, setting_name, key_name, NULL); if (!value) return NULL; + current = value; + /* get address field */ - address_str = read_field (¤t, &error, IP_ADDRESS_CHARS, DELIMITERS); - if (error) { + address_str = read_field (¤t, &err_str, IP_ADDRESS_CHARS, DELIMITERS); + if (err_str) { handle_warn (info, property_name, NM_KEYFILE_WARN_SEVERITY_WARN, _("unexpected character '%c' for address %s: '%s' (position %td)"), - *error, key_name, VALUE_ORIG (), error - current); + *err_str, key_name, VALUE_ORIG (), err_str - current); return NULL; } /* get prefix length field (skippable) */ - plen_str = read_field (¤t, &error, DIGITS, DELIMITERS); + plen_str = read_field (¤t, &err_str, DIGITS, DELIMITERS); /* get gateway field */ - gateway_str = read_field (¤t, &error, IP_ADDRESS_CHARS, DELIMITERS); - if (error) { + gateway_str = read_field (¤t, &err_str, IP_ADDRESS_CHARS, DELIMITERS); + if (err_str) { handle_warn (info, property_name, NM_KEYFILE_WARN_SEVERITY_WARN, _("unexpected character '%c' for %s: '%s' (position %td)"), - *error, key_name, VALUE_ORIG (), error - current); + *err_str, key_name, VALUE_ORIG (), err_str - current); return NULL; } /* for routes, get metric */ if (route) { - metric_str = read_field (¤t, &error, DIGITS, DELIMITERS); - if (error) { + metric_str = read_field (¤t, &err_str, DIGITS, DELIMITERS); + if (err_str) { handle_warn (info, property_name, NM_KEYFILE_WARN_SEVERITY_WARN, _("unexpected character '%c' in prefix length for %s: '%s' (position %td)"), - *error, key_name, VALUE_ORIG (), error - current); + *err_str, key_name, VALUE_ORIG (), err_str - current); return NULL; } } else @@ -393,7 +401,7 @@ read_one_ip_address_or_route (KeyfileReaderInfo *info, /* parse plen, fallback to defaults */ if (plen_str) { - if (!get_one_int (info, property_name, plen_str, ipv6 ? 128 : 32, &plen) + if ( !get_one_int (info, property_name, plen_str, ipv6 ? 128 : 32, &plen) || (route && plen == 0)) { plen = DEFAULT_PREFIX (route, ipv6); if ( info->error |