[patch 1/1] Fix gcc4 warning, def & len may be used uninitialized in this function

domen at coderock.org domen at coderock.org
Sat May 28 23:17:07 GMT 2005


From: Jesse Millan <jessem at cs.pdx.edu>



This patch eliminates the warning that is generated
when passing a reference of an uninitialized variable to a function
where it possible that the function will return without initializing
that variable.

The first execution path leaves both def and len uninitialized. The
second leaves len uninitialized. In both cases, initializing them when
they otherwise would not have been is close to pointless because they
would not get used anyway. The change is only to suppress the compiler
warning.

Signed-off-by: Jesse Millan <jessem at cs.pdx.edu>
Signed-off-by: Domen Puncer <domen at coderock.org>

---
 asn1.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

Index: quilt/fs/cifs/asn1.c
===================================================================
--- quilt.orig/fs/cifs/asn1.c
+++ quilt/fs/cifs/asn1.c
@@ -160,12 +160,18 @@ asn1_length_decode(struct asn1_ctx *ctx,
 {
 	unsigned char ch, cnt;
 
-	if (!asn1_octet_decode(ctx, &ch))
+	if (!asn1_octet_decode(ctx, &ch)) {
+		/* Function would have returned without initializing 'def' and 'len' */
+		*def = 0;
+		*len = 0;
 		return 0;
+	}
 
-	if (ch == 0x80)
+	if (ch == 0x80) {
 		*def = 0;
-	else {
+		/* Function would have returned without initializing 'len' */
+		*len = 0;
+	} else {
 		*def = 1;
 
 		if (ch < 0x80)

--


More information about the samba-technical mailing list