summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-04-01 12:26:20 +0200
committerThomas Haller <thaller@redhat.com>2020-05-02 17:04:45 +0200
commite2bfbd9c81aa30154c31a5e77217484c6a7c7ece (patch)
tree7109a9a3b40894e797a3fefa0f6b36ccadef3af2
parent4633d6a8b5adb12137bcd5ef61cb917bc826a3c3 (diff)
downloadNetworkManager-e2bfbd9c81aa30154c31a5e77217484c6a7c7ece.tar.gz
shared: add nm_g_ascii_strtod() to workaround bug
(cherry picked from commit 35a9f632a81df40209e3d71f2328ccdfcf175aee) (cherry picked from commit f8cae1ed18ad5d29c246e9d9036f670badd28126) (cherry picked from commit 0de1c3a53a6196694cbe4ecb2dade727a7469e65)
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c37
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h3
2 files changed, 40 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index 83913e6673..f8be16ba18 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -780,6 +780,43 @@ again:
return v;
}
+/* see nm_g_ascii_strtoll(). */
+double
+nm_g_ascii_strtod (const char *nptr,
+ char **endptr)
+{
+ int try_count = 2;
+ double v;
+ int errsv;
+
+ nm_assert (nptr);
+
+again:
+ v = g_ascii_strtod (nptr, endptr);
+ errsv = errno;
+
+ if (errsv == 0)
+ return v;
+
+ if (errsv == ERANGE)
+ return v;
+
+ if (try_count-- > 0)
+ goto again;
+
+#if NM_MORE_ASSERTS
+ g_critical ("g_ascii_strtod() for \"%s\" failed with errno=%d (%s) and v=%f",
+ nptr,
+ errsv,
+ nm_strerror_native (errsv),
+ v);
+#endif
+
+ /* Not really much else to do. Return the parsed value and leave errno set
+ * to the unexpected value. */
+ return v;
+}
+
/* _nm_utils_ascii_str_to_int64:
*
* A wrapper for g_ascii_strtoll, that checks whether the whole string
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 76cd8d368c..0860515562 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -543,6 +543,9 @@ gint64 nm_g_ascii_strtoll (const char *nptr,
char **endptr,
guint base);
+double nm_g_ascii_strtod (const char *nptr,
+ char **endptr);
+
gint64 _nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback);
guint64 _nm_utils_ascii_str_to_uint64 (const char *str, guint base, guint64 min, guint64 max, guint64 fallback);