[Pkg-libvirt-commits] [libguestfs] 07/26: When calling getline first time, initialize length to zero.

Hilko Bengen bengen at moszumanska.debian.org
Sun Nov 1 17:11:25 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag upstream/1.28.12
in repository libguestfs.

commit 283ea40b05ece7755f562562dd0eb7b0d2a0959a
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Thu May 14 13:22:00 2015 +0100

    When calling getline first time, initialize length to zero.
    
    The man page for getline says:
    
       ssize_t getline(char **lineptr, size_t *n, FILE *stream);
     [...]
       If  *lineptr  is set to NULL and *n is set 0 before the call, then get‐
       line() will allocate a buffer for storing the line.  This buffer should
       be freed by the user program even if getline() failed.
    
    which seems to indicate that we must initialize both line and len to 0
    before the first call to getline.
    
    In several places we were not initializing len.  The program still
    worked fine, but it seems better to initialize the length anyway.
    
    (cherry picked from commit 5bf7f770b6829c9454e6ae0d778154a4711c601c)
---
 df/estimate-max-threads.c | 2 +-
 examples/libvirt-auth.c   | 2 +-
 fuse/test-fuse.c          | 2 +-
 p2v/main.c                | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/df/estimate-max-threads.c b/df/estimate-max-threads.c
index 7d5b090..ca1fd42 100644
--- a/df/estimate-max-threads.c
+++ b/df/estimate-max-threads.c
@@ -60,7 +60,7 @@ read_line_from (const char *cmd)
 {
   FILE *pp;
   char *ret = NULL;
-  size_t allocsize;
+  size_t allocsize = 0;
 
   pp = popen (cmd, "r");
   if (pp == NULL)
diff --git a/examples/libvirt-auth.c b/examples/libvirt-auth.c
index 699dd87..8a5db77 100644
--- a/examples/libvirt-auth.c
+++ b/examples/libvirt-auth.c
@@ -109,7 +109,7 @@ auth_callback (guestfs_h *g,
   size_t i;
   char *prompt;
   char *reply = NULL;
-  size_t allocsize;
+  size_t allocsize = 0;
   char *pass;
   ssize_t len;
   int r;
diff --git a/fuse/test-fuse.c b/fuse/test-fuse.c
index 50a5ab5..517423f 100644
--- a/fuse/test-fuse.c
+++ b/fuse/test-fuse.c
@@ -250,7 +250,7 @@ test_fuse (void)
   fflush (stdout)
   FILE *fp;
   char *line = NULL;
-  size_t len;
+  size_t len = 0;
   struct stat statbuf;
   char buf[128];
   ssize_t r;
diff --git a/p2v/main.c b/p2v/main.c
index 4e11c0a..853af11 100644
--- a/p2v/main.c
+++ b/p2v/main.c
@@ -289,7 +289,7 @@ partition_parent (dev_t part_dev)
 {
   CLEANUP_FCLOSE FILE *fp = NULL;
   CLEANUP_FREE char *path = NULL, *content = NULL;
-  size_t len;
+  size_t len = 0;
   unsigned parent_major, parent_minor;
 
   if (asprintf (&path, "/sys/dev/block/%d:%d/../dev",
@@ -504,7 +504,7 @@ read_cmdline (void)
 {
   CLEANUP_FCLOSE FILE *fp = NULL;
   char *ret = NULL;
-  size_t len;
+  size_t len = 0;
 
   fp = fopen ("/proc/cmdline", "re");
   if (fp == NULL) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list