[Libguestfs] [PATCH nbdkit] server/public.c: Uninline nbdkit_strdup_intern to avoid compiler warning.

Richard W.M. Jones rjones at redhat.com
Thu Sep 3 09:41:03 UTC 2020


Previously with GCC 10.2 this code produced:

In function ‘nbdkit_strndup_intern’,
    inlined from ‘nbdkit_strdup_intern’ at public.c:839:10:
public.c:827:10: error: ‘strndup’ specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
  827 |   copy = strndup (str, n);
      |          ^~~~~~~~~~~~~~~~
---
 server/public.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/server/public.c b/server/public.c
index e871fdeb..270f81a4 100644
--- a/server/public.c
+++ b/server/public.c
@@ -836,7 +836,21 @@ nbdkit_strndup_intern (const char *str, size_t n)
 const char *
 nbdkit_strdup_intern (const char *str)
 {
-  return nbdkit_strndup_intern (str, SIZE_MAX);
+  char *copy;
+
+  if (str == NULL) {
+    nbdkit_error ("nbdkit_strdup_intern: no string given");
+    errno = EINVAL;
+    return NULL;
+  }
+
+  copy = strdup (str);
+  if (copy == NULL) {
+    nbdkit_error ("strdup: %m");
+    return NULL;
+  }
+
+  return add_intern (copy);
 }
 
 const char *
-- 
2.27.0




More information about the Libguestfs mailing list