Re: [PATCH 01/19] util: buffer: Simplify convoluted condition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2019-10-24 at 15:56 +0200, Peter Krempa wrote:
> Spare a few more lines rather than having a condition with a nested
> ternary.
> 
> Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
> ---
>  src/util/virbuffer.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
> index 04c8fd7291..a58481430a 100644
> --- a/src/util/virbuffer.c
> +++ b/src/util/virbuffer.c
> @@ -64,11 +64,19 @@ virBufferAdjustIndent(virBufferPtr buf, int
> indent)
>  {
>      if (!buf || buf->error)
>          return;
> -    if (indent > 0 ? INT_MAX - indent < buf->indent
> -        : buf->indent < -indent) {
> -        virBufferSetError(buf, -1);
> -        return;
> +
> +    if (indent > 0) {
> +        if (INT_MAX - indent < buf->indent) {
> +            virBufferSetError(buf, -1);
> +            return;
> +        }
> +    } else {
> +        if (buf->indent < -indent) {
> +            virBufferSetError(buf, -1);
> +            return;
> +        }
>      }
> +
>      buf->indent += indent;
>  }
> 

It took me a few reads to make sure I understood the original code, so
this is definitely an improvement.

Reviewed-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux