summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-04-01 13:50:16 +0200
committerThomas Haller <thaller@redhat.com>2020-04-01 17:18:01 +0200
commit3b58c5fef490cfdae632f5007c77267e47971734 (patch)
tree9ee4503f5a638385db0abded24193099456be7f2
parent35a9f632a81df40209e3d71f2328ccdfcf175aee (diff)
downloadNetworkManager-3b58c5fef490cfdae632f5007c77267e47971734.tar.gz
shared: add nm_g_ascii_strtoull() to workaround bug
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c49
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h4
2 files changed, 53 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index 783887214b..52f4bff2fd 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -1021,6 +1021,55 @@ again:
return v;
}
+/* See nm_g_ascii_strtoll() */
+guint64
+nm_g_ascii_strtoull (const char *nptr,
+ char **endptr,
+ guint base)
+{
+ int try_count = 2;
+ guint64 v;
+ const int errsv_orig = errno;
+ int errsv;
+
+ nm_assert (nptr);
+ nm_assert (base == 0u || (base >= 2u && base <= 36u));
+
+again:
+ errno = 0;
+ v = g_ascii_strtoull (nptr, endptr, base);
+ errsv = errno;
+
+ if (errsv == 0) {
+ if (errsv_orig != 0)
+ errno = errsv_orig;
+ return v;
+ }
+
+ if ( errsv == ERANGE
+ && NM_IN_SET (v, G_MAXUINT64))
+ return v;
+
+ if ( errsv == EINVAL
+ && v == 0
+ && nptr
+ && nptr[0] == '\0')
+ return v;
+
+ if (try_count-- > 0)
+ goto again;
+
+#if NM_MORE_ASSERTS
+ g_critical ("g_ascii_strtoull() for \"%s\" failed with errno=%d (%s) and v=%"G_GUINT64_FORMAT,
+ nptr,
+ errsv,
+ nm_strerror_native (errsv),
+ v);
+#endif
+
+ return v;
+}
+
/* see nm_g_ascii_strtoll(). */
double
nm_g_ascii_strtod (const char *nptr,
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 79ea31771e..b68e658c38 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -661,6 +661,10 @@ gint64 nm_g_ascii_strtoll (const char *nptr,
char **endptr,
guint base);
+guint64 nm_g_ascii_strtoull (const char *nptr,
+ char **endptr,
+ guint base);
+
double nm_g_ascii_strtod (const char *nptr,
char **endptr);