[PATCH 12/18] user-cr: Fix nread unitialized case

Matt Helsley matthltc at us.ibm.com
Thu Mar 17 10:27:44 PDT 2011


When len == 0 nread can have an uninitialized value that gets used.
Initialize it. Note that zero-length reads happen when there's
nothing in the checkpoint header except the type and len fields.
This means the first read is sizeof(ckpt_hdr) and the second,
"payload", read is zero length.

Signed-off-by: Matt Helsley <matthltc at us.ibm.com>
---
 ckptinfo.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/ckptinfo.c b/ckptinfo.c
index d73b38c..23db9fb 100644
--- a/ckptinfo.c
+++ b/ckptinfo.c
@@ -157,7 +157,7 @@ int main(int argc, char *argv[])
 
 static int __image_read(int fd, void *buf, int len)
 {
-	ssize_t nread;
+	ssize_t nread = 0;
 	int nleft;
 
 	for (nleft = len; nleft; nleft -= nread) {
-- 
1.6.3.3



More information about the Containers mailing list