Ethereal-dev: Re: [Ethereal-dev] information is display while filter, not otherwise

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <gharris@xxxxxxxxx>
Date: Thu, 31 Mar 2005 18:15:36 -0800
Nina Pham wrote:

I thought I use tree parrameter in the wrong way. I created a tree then pass it in a function. But then I don't know what I suppose to do. I attached here part of the file in which I use tree parameter. In function dissect_KLATST, I created a tree call reqrsp_tree and passed it to function parseData. Thanks

void parseData(tvbuff_t *tvb, packet_info *pinfo, gboolean is_response, MciReq curMciReq, guint16 dataSize, proto_tree *ReqRsp_tree) /* ** Parse data and print them in the info column */
{

	...


            // display size
            if (check_col(pinfo->cinfo, COL_INFO)) {
                col_append_fstr(pinfo->cinfo, COL_INFO, " size=%u", dataSize);
            }

	...

}

That routine puts items into the Info column, so it should be called regardless of whether "tree" is null or not.

However:

/* Code to actually dissect the packets */
static void
dissect_KLATST(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{

	...

	tvbLen = tvb_length(tvb);

    /* Get the TST packet signature*/
    TST_signature = tvb_get_letohl(tvb, SIGNATURE_OFFSET);
    /* Get the TST type*/
    TST_type = tvb_get_letohs(tvb, TYPE_OFFSET);
    /* Get the TST size*/
    TST_size = tvb_get_letohs(tvb, SIZE_OFFSET);

(A side note here - if "tvb_length(tvb)" isn't at least 8, one of those calls will throw an exception, so testing "tvbLen" later isn't necessary.)

	...

        if (tree) {

	...

            /* parse data and put them in info column  and summary display*/
#if 1
parseData(tvb, pinfo, is_response, curTSTReq, TST_size, ReqRsp_tree);
        }
#else
        }
parseData(tvb, pinfo, is_response, curTSTReq, TST_size, ReqRsp_tree);
#endif
    }
}

..."parseData()" will only be called if "tree" is non-null. You should call it regarless of whether "tree" is null.

I.e., the code compiled in by the "#if 1" is wrong, and the code that it #if's out is right.

You should also make sure that "ReqRsp_tree" is null if "tree" is null.