[Libguestfs] [PATCH nbdinfo 1/2] common/utils: Add function to convert sizes to human-readable

Richard W.M. Jones rjones at redhat.com
Mon Sep 20 11:00:18 UTC 2021


On Mon, Sep 20, 2021 at 12:50:47PM +0200, Martin Kletzander wrote:
> And just set here:
> 
> *human = i == 6;
> 
> Even better make it more future-proof and use (sizeof(ext) / sizeof(*ext))
> instead of just "6".  Disclaimer: Written by hand, not tested.

In my v2 I will change it to:

+  /* Set to flag to true if we're going to add a human-readable extension. */
+  if (human)
+    *human = ext[i][0] != '\0';

> >+  snprintf (buf, HUMAN_SIZE_LONGEST-1, "%" PRIu64 "%s", bytes, ext[i]);
> 
> The '-1' seems unnecessary here as snprintf() counts the zero terminator as part
> the supplied size and will not overrun @size-sized buffers.

Oops, that's left over from when I thought I was going to save one
byte for adding the extension.  Will fix in v2.

Thanks,

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW




More information about the Libguestfs mailing list