[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    [PATCH] - fix warning in kdelibs-3.1rc5/dcop/KDE-ICE/protosetup.c and eliminate unneeded variable
From:       Jesper Juhl <jju () dif ! dk>
Date:       2002-12-10 22:06:11
[Download RAW message or body]

Hi list,

Here's yet another small patch for a minor warning.

Patch is against kdelibs from KDE3.1-rc5

This time the warning that caught my eye was this one :

protosetup.c: In function `KDE_IceProtocolSetup':
protosetup.c:58: warning: `versionRec' might be used uninitialized in this 
function

I checked the code, and there's no chance whatsoever of this warning being 
used uninitialized. But with a few small codechanges the warning can be 
silenced and we can get rid of an unneeded variable that is used for the sole 
purpose of making sure that versionRec has been initialized.

In the original code a variable called "accepted" was used as a bool and only 
set to 1 in the place where versionRec gets a value assigned. So by 
initializing versionRec to NULL when it is defined and then checking if 
versionRec != NULL instead of checking accepted, we silence the warning and 
can get rid of accepted.

A patch (kdelibs-dcop-KDE-ICE-protosetup.c-1.patch) that does this is attached 
for review and/or inclusion.

Some might argue that a variable called "accepted" is more readable, and I may 
agree, but since accepted seems to exist only for the bennefit of versionRec 
using that instead should be equally readable to someone who knows what the 
code's supposed to do.

As always, comments, (constructive) criticism, suggestions etc. are more than 
welcome :)


/Jesper Juhl

["kdelibs-dcop-KDE-ICE-protosetup.c-1.patch" (text/x-diff)]

--- orig/kdelibs-3.1rc5/dcop/KDE-ICE/protosetup.c	2001-03-13 02:12:22.000000000 +0100
+++ kdelibs-3.1rc5/dcop/KDE-ICE/protosetup.c	2002-12-10 22:50:19.000000000 +0100
@@ -50,12 +50,12 @@
     _IceProtocol	*myProtocol;
     int			extra;
     Bool		gotReply, ioErrorOccured;
-    int			accepted, i;
+    int			i;
     int			hisOpcode;
     unsigned long	setup_sequence;
     IceReplyWaitInfo 	replyWait;
     _IceReply		reply;
-    IcePoVersionRec	*versionRec;
+    IcePoVersionRec	*versionRec = NULL;
     int			authCount;
     int			*authIndices;
 
@@ -188,7 +188,6 @@
 
     gotReply = False;
     ioErrorOccured = False;
-    accepted = 0;
 
     while (!gotReply && !ioErrorOccured)
     {
@@ -220,8 +219,6 @@
 		{
 		    versionRec = &(myProtocol->orig_client->version_recs[
 		        reply.protocol_reply.version_index]);
-
-		    accepted = 1;
 		}
 	    }
 	    else /* reply.type == ICE_PROTOCOL_ERROR */
@@ -241,7 +238,7 @@
 	}
     }
 
-    if (accepted)
+    if (versionRec)
     {
 	_IceProcessMsgInfo *process_msg_info;
 

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic