[libvirt] [PATCH 2/3] esx: Add esxVI_checkArgList macro

Michal Prívozník mprivozn at redhat.com
Tue Jul 3 09:31:36 UTC 2018


On 07/03/2018 04:20 AM, Marcos Paulo de Souza wrote:
> This macro avoids code duplication when checking for arrays of objects.
> 
> Signed-off-by: Marcos Paulo de Souza <marcos.souza.org at gmail.com>
> ---
>  src/esx/esx_vi.c | 189 ++++++++++++-----------------------------------
>  1 file changed, 46 insertions(+), 143 deletions(-)
> 
> diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
> index 25fbdc7e44..212300dbff 100644
> --- a/src/esx/esx_vi.c
> +++ b/src/esx/esx_vi.c
> @@ -41,6 +41,16 @@
>  
>  VIR_LOG_INIT("esx.esx_vi");
>  
> +#define esxVI_checkArgList(val) \
> +    do { \
> +        if (!val || *val) { \
> +            virReportError(VIR_ERR_INVALID_ARG, "%s", _("Invalid argument")); \

Actually, this is one of the few places where VIR_ERR_INTERNAL_ERROR is
not misused and makes sense. The only way how this error can be reported
is if there's a bug in our code, not because of some input user made.

There are also other occurrences of this pattern. coccinelle helped to
find other. I used the following spatch:

@@
identifier ptr;
@@

- (!ptr || *ptr)
+ (esxVI_checkArgList(ptr))


Mind putting them here too? Otherwise the patch looks good.

Michal




More information about the libvir-list mailing list