After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 704075 - Logically Dead code in valid.c
Logically Dead code in valid.c
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: general
git master
Other Linux
: Normal enhancement
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2013-07-12 09:14 UTC by Gaurav
Modified: 2013-09-30 03:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Drop checks for already checked (1.83 KB, patch)
2013-08-06 07:09 UTC, Denis Pauk
none Details | Review

Description Gaurav 2013-07-12 09:14:36 UTC
In file https://git.gnome.org/browse/libxml2/tree/valid.c

At two places the there are conditions which are checked twice.
Hence, checking the same condition again, is logically dead code.


1. In function xmlRemoveID(xmlDocPtr doc, xmlAttrPtr attr)

line no 2735-2748
int
xmlRemoveID(xmlDocPtr doc, xmlAttrPtr attr) {
    ----- Some Code -------
    if (doc == NULL) return(-1);
    if (attr == NULL) return(-1);
    table = (xmlIDTablePtr) doc->ids;
    if (table == NULL)
        return(-1);

    if (attr == NULL)
	return(-1);
    ---- Some Code -----
}

Here after first check to (attr==NULL), value of attr will never be NULL(0). So checking the same condition again is logically dead code.

2. Similar thing is happening in function xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr)

line no 3053-3067

int
xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr) {
    ------Some Code -------
    if (doc == NULL) return(-1);
    if (attr == NULL) return(-1);
    table = (xmlRefTablePtr) doc->refs;
    if (table == NULL)
        return(-1);

    if (attr == NULL)
        return(-1);
    -----Some Code ------
}

The solution to this is not to check the same condition twice. Remove the re-occurence of same condition in both functions.
Comment 1 Denis Pauk 2013-08-06 07:09:45 UTC
Created attachment 250922 [details] [review]
Drop checks for already checked
Comment 2 Daniel Veillard 2013-09-30 03:03:35 UTC
Indeed, that and reformatting cleanup very welcome !

Applied and pushed:

https://git.gnome.org/browse/libxml2/commit/?id=0146179120d4f1162f0400a0131bea2e5d600155

 thanks for the report and the patch !

Daniel