[libvirt] [PATCH 4/9] Remove VIR_STRNDUP usage with checked pointers

Daniel Henrique Barboza danielhb413 at gmail.com
Wed Nov 13 12:41:55 UTC 2019


This patch failed to compile for me with the following error:


../../tools/vsh.c:70:1: error: 'vshErrorOOM' defined but not used [-Werror=unused-function]
    70 | vshErrorOOM(void)
       | ^~~~~~~~~~~


Apparently you removed the last call to vshErrorOOM() in the tools/vsh.c changes here. For
reference, I am testing this series on top of this commit:


commit 54dd0938375daaa68674b271f444b312d6684b01 (origin/master, origin/HEAD, master)
Author: Ján Tomko <jtomko at redhat.com>
Date:   Wed Nov 13 09:51:45 2019 +0100

     locking: fix build with older sanlock



Removing the function makes the patch compile without errors:


diff --git a/tools/vsh.c b/tools/vsh.c
index 2b1e0506ba..5005b1deaa 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -65,17 +65,6 @@ const vshCmdGrp *cmdGroups;
  const vshCmdDef *cmdSet;
  
  
-/* simple handler for oom conditions */
-static void
-vshErrorOOM(void)
-{
-    fflush(stdout);
-    fputs(_("error: Out of memory\n"), stderr);
-    fflush(stderr);
-    exit(EXIT_FAILURE);
-}
-
-
  double
  vshPrettyCapacity(unsigned long long val, const char **unit)
  {



Aside from this, patch LGTM.



Thanks,


DHB


On 11/12/19 2:02 PM, Ján Tomko wrote:
> Remove the usage where sanity of the length argument is verified
> by other conditions not matching the previous patches.
> 
> Signed-off-by: Ján Tomko <jtomko at redhat.com>
> ---
>   src/libxl/xen_common.c | 18 ++++++++----------
>   tools/vsh.c            |  5 ++---
>   2 files changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
> index a4a9ec59bf..7ac24fb606 100644
> --- a/src/libxl/xen_common.c
> +++ b/src/libxl/xen_common.c
> @@ -817,9 +817,8 @@ xenParseSxprChar(const char *value,
>               goto error;
>           }
>   
> -        if (offset != value &&
> -            VIR_STRNDUP(def->source->data.tcp.host, value, offset - value) < 0)
> -            goto error;
> +        if (offset != value)
> +            def->source->data.tcp.host = g_strndup(value, offset - value);
>   
>           offset2 = strchr(offset, ',');
>           offset++;
> @@ -845,9 +844,9 @@ xenParseSxprChar(const char *value,
>               goto error;
>           }
>   
> -        if (offset != value &&
> -            VIR_STRNDUP(def->source->data.udp.connectHost, value, offset - value) < 0)
> -            goto error;
> +        if (offset != value)
> +            def->source->data.udp.connectHost = g_strndup(value,
> +                                                          offset - value);
>   
>           offset2 = strchr(offset, '@');
>           if (offset2 != NULL) {
> @@ -862,10 +861,9 @@ xenParseSxprChar(const char *value,
>                   goto error;
>               }
>   
> -            if (offset3 > (offset2 + 1) &&
> -                VIR_STRNDUP(def->source->data.udp.bindHost,
> -                            offset2 + 1, offset3 - offset2 - 1) < 0)
> -                goto error;
> +            if (offset3 > (offset2 + 1))
> +                def->source->data.udp.bindHost = g_strndup(offset2 + 1,
> +                                                           offset3 - offset2 - 1);
>   
>               def->source->data.udp.bindService = g_strdup(offset3 + 1);
>           } else {
> diff --git a/tools/vsh.c b/tools/vsh.c
> index 000cf6a009..2b1e0506ba 100644
> --- a/tools/vsh.c
> +++ b/tools/vsh.c
> @@ -360,9 +360,8 @@ vshCmddefCheckInternals(vshControl *ctl,
>                            cmd->name);
>                   return -1; /* alias options are tracked by the original name */
>               }
> -            if ((p = strchr(name, '=')) &&
> -                VIR_STRNDUP(name, name, p - name) < 0)
> -                vshErrorOOM();
> +            if ((p = strchr(name, '=')))
> +                name = g_strndup(name, p - name);
>               for (j = i + 1; cmd->opts[j].name; j++) {
>                   if (STREQ(name, cmd->opts[j].name) &&
>                       cmd->opts[j].type != VSH_OT_ALIAS)
> 





More information about the libvir-list mailing list