[libvirt PATCH] util: Drop pointless NUL_TERMINATE macro

Jiri Denemark posted 1 patch 2 years, 6 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/7b32647502884412fdb7e99cf519e404e069eb3b.1635175925.git.jdenemar@redhat.com
src/internal.h     | 2 --
src/util/virutil.c | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
[libvirt PATCH] util: Drop pointless NUL_TERMINATE macro
Posted by Jiri Denemark 2 years, 6 months ago
It's only used once and open coding it is at least as clear as using the
macro.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/internal.h     | 2 --
 src/util/virutil.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/internal.h b/src/internal.h
index e1250a59fe..d3809bf057 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -91,8 +91,6 @@
 #define STREQ_NULLABLE(a, b) (g_strcmp0(a, b) == 0)
 #define STRNEQ_NULLABLE(a, b) (g_strcmp0(a, b) != 0)
 
-#define NUL_TERMINATE(buf) do { (buf)[sizeof(buf)-1] = '\0'; } while (0)
-
 #ifdef WIN32
 # ifndef O_CLOEXEC
 #  define O_CLOEXEC _O_NOINHERIT
diff --git a/src/util/virutil.c b/src/util/virutil.c
index c9de043c40..e04f1343d8 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -485,7 +485,7 @@ virGetHostnameImpl(bool quiet)
                                  "%s", _("failed to determine host name"));
         return NULL;
     }
-    NUL_TERMINATE(hostname);
+    hostname[sizeof(hostname) - 1] = '\0';
 
     if (STRPREFIX(hostname, "localhost") || strchr(hostname, '.')) {
         /* in this case, gethostname returned localhost (meaning we can't
-- 
2.33.1

Re: [libvirt PATCH] util: Drop pointless NUL_TERMINATE macro
Posted by Peter Krempa 2 years, 6 months ago
On Mon, Oct 25, 2021 at 17:32:05 +0200, Jiri Denemark wrote:
> It's only used once and open coding it is at least as clear as using the
> macro.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/internal.h     | 2 --
>  src/util/virutil.c | 2 +-
>  2 files changed, 1 insertion(+), 3 deletions(-)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>