From kde-devel Tue Dec 10 22:06:11 2002 From: Jesper Juhl Date: Tue, 10 Dec 2002 22:06:11 +0000 To: kde-devel Subject: [PATCH] - fix warning in kdelibs-3.1rc5/dcop/KDE-ICE/protosetup.c and eliminate unneeded variable X-MARC-Message: https://marc.info/?l=kde-devel&m=103955765931901 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_TVm99skljuTLios" --Boundary-00=_TVm99skljuTLios Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 --Boundary-00=_TVm99skljuTLios Content-Type: text/x-diff; charset="us-ascii"; name="kdelibs-dcop-KDE-ICE-protosetup.c-1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kdelibs-dcop-KDE-ICE-protosetup.c-1.patch" --- 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; --Boundary-00=_TVm99skljuTLios-- >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<