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

Re: [Libguestfs] [PATCH 1/2] New API: vfs_min_size



On Tue, Oct 20, 2015 at 12:59:06PM +0300, Maxim Perevedentsev wrote:
> 
> 
> On 10/19/2015 07:45 PM, Pino Toscano wrote:
> >On Monday 19 October 2015 17:05:02 Maxim Perevedentsev wrote:
> >>+int64_t
> >>+ntfs_min_size (const char *device)
> >>+{
> >>+  CLEANUP_FREE char *err = NULL, *out = NULL;
> >>+  CLEANUP_FREE_STRING_LIST char **lines = NULL;
> >>+  int r;
> >>+  size_t i;
> >>+  char *p;
> >>+  int64_t ret, volume_size = 0;
> >The scope of "ret" could be reduced to only the if below where it is
> >used.
> Looking through code, I decided that declaring variables in the
> beginning of function is part of code style, so I followed it.
> Should I also move volume/cluster size declarations to branch where
> they are used?

The code style is to put variable decls at the top.

What Pino means here specifically is that the 'ret' could be
placed inside the later loop, ie:

+  for (i = 0; lines[i] != NULL; ++i) {
+    if ((p = strstr (lines[i], size_pattern))) {
       int64_t ret;

+      if (sscanf (p + strlen(size_pattern), "%" SCNd64, &ret) != 1) {
+        reply_with_error("Cannot parse minimum size");
+        return -1;
+      }
+      return ret;
+    }

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top


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