Ethereal-dev: Re: [ethereal-dev] Patch for file.c

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

From: Ben Fowler <wapdev@xxxxxxxxxxxx>
Date: Sat, 13 May 2000 17:56:10 +0100
At 11:21 PM 5/12/00, Gilbert Ramirez wrote:
On Fri, May 12, 2000 at 12:30:59PM -0500, Ben Fowler wrote:
> The enclosed patches changes do the following:
[ ...]
1. Why assert on hfindex in each of the proto_tree_add_*() calls?
They don't actually use hfindex, they just pass the value to
proto_registrar_get_nth(). Let's let the function that _uses_
the value make assertions about the validity of the data.

Where code is working, and "wrapped up", that is fine; but whilst
I am changing and experimenting, I want to assert at the "way in",
like turnstiles at a sports arena. My take is that it is the function
or the module that accepts the data that should assert it, not
necessarily the (likely debugged) routine that uses it.

2. Even through g_assert() prints the line number where
the assertion occurs, you'll still want to do a backtrace in your
debugger to see who called the proto_tree_add_*() function. In that
case, it doesn't matter where in the chain the assert is, because
you'll still get the important information about which function
sent the erroneous data only through the debugger.

This assumes that all of us are as familiar with the proto_tree_add_*
functions as you are. I would like the first function called by code
that I have written to do the assertion. I assume that assertion
statements are cheap and tend to make code self-documentation;
I use lots of them.

> 3) Include stdio.h in tvbuff.c (to support fprintf( ) )

Why? I don't see fprintf() being used. Is some macro expanding
to fprintf()?

Sure, the full diff went -

@@ -37,6 +37,7 @@
 #include "tvbuff.h"
 #endif

+#include <stdio.h>
 #include <string.h>

 /* Pointer versions of ntohs and ntohl.  Given a pointer to a member of a
@@ -586,6 +587,7 @@
 gint
 tvb_raw_offset(tvbuff_t *tvb)
 {
+       fprintf( stderr, "tvb_raw_offset: tvb is %p\n", tvb );
        if (tvb->raw_offset == -1) {
                tvb->raw_offset = offset_from_real_beginning(tvb, 0);
        }

and I thought that you would not be interested in the particular logging
statement that I had inserted whilst trying to find out why all of my
proto_tree_add_* functions had stopped working at once; but you might be
happy with the innocuous include statement that supports it.

Cheers,

Ben.



--
Leedsnet - The information resource for Leeds and the West Riding
< URL:http://www.leedsnet.com/mobile/ >