W3C home > Mailing lists > Public > www-lib@w3.org > October to December 2001

Bugs in HTAnchor_delete

From: ┴ĄŻ┬╚» <thedeft@softwise.co.kr>
Date: Thu, 4 Oct 2001 20:14:25 +0900
Message-ID: <000b01c14cc5$ba7d0bb0$50a1e7cb@notquitetrash>
To: <www-lib@w3.org>
There seem to be two bugs in HTAnchor_delete in HTAnchor.c. I think that one of the bugs has been already mentioned by someone on this mailing list.

On lines 503 - 506,

            while ((child=(HTChildAnchor *) HTList_removeLastObject(kids)))
            delete_links((HTAnchor *) child);
            HT_FREE(child->tag);
            HT_FREE(child);

I believe this is meant to be

            while ((child=(HTChildAnchor *) HTList_removeLastObject(kids))) {
            delete_links((HTAnchor *) child);
            HT_FREE(child->tag);
            HT_FREE(child);
            }

The other is a wrong placement of a bracket.

    if (!HTList_isEmpty(me->sources)) {    /* There are still incoming links */

    /*
    ** Delete all outgoing links from children, if any
    */
    if (me->children) {
        int cnt = 0;
        for (; cnt<CHILD_HASH_SIZE; cnt++) {
        HTList * kids = me->children[cnt];
        if (kids) {
            HTChildAnchor * child;
            while ((child = (HTChildAnchor *) HTList_nextObject(kids)))
            delete_links((HTAnchor *) child);
            return NO;  /* Parent not deleted */
        }
        }
    }

    /*
    ** No more incoming links : kill everything
    ** First, recursively delete children
    */
    if (me->children) {
        int cnt = 0;
        for (; cnt<CHILD_HASH_SIZE; cnt++) {
        HTList * kids = me->children[cnt];
        if (kids) {
            HTChildAnchor * child;
            while ((child=(HTChildAnchor *) HTList_removeLastObject(kids)))
            delete_links((HTAnchor *) child);
            HT_FREE(child->tag);
            HT_FREE(child);
        }
        }
    }
    } <----

The comments indicate that the anchor is allowed to be erased only when there are no more incoming sources for the anchor. However, "if (!HTList_isEmpty(me->sources)) {" encloses statements that belong to the no-more-incoming-links case. The bracket at the line 510 should probably be moved somewhere around the line 492.
Received on Thursday, 4 October 2001 07:09:12 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 23 April 2007 18:18:40 GMT