Wireshark-dev: Re: [Wireshark-dev] [Wireshark-commits] rev 21556: /trunk/epan//trunk/epan/: pro

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Tue, 8 May 2007 19:45:37 -0700

On Apr 25, 2007, at 11:06 AM, Anders Broman wrote:

Hi,
I'm looking inot spliting it into:

/*This function will call proto_tree_add_bits_ret_val() without the return
value. */
extern proto_item *
proto_tree_add_bits(proto_tree *tree, int hf_index, tvbuff_t *tvb, gint
bit_offset, gint no_of_bits, gboolean little_endian);

/* Calls tvb_get bits */
extern proto_item *
proto_tree_add_bits_ret_val(proto_tree *tree, int hf_index, tvbuff_t *tvb,
gint bit_offset, gint no_of_bits, guint32 *return_value, gboolean
little_endian);


guint32
tvb_get_bits(tvbuff_t *tvb, gint bit_offset, gint no_of_bits, gboolean
little_endian)

(Should it handle 64bits?)

Or should there be:

guint8 tvb_get_bits8(tvbuff_t *tvb, gint bit_offset, gint no_of_bits, gboolean
little_endian)

		where "no_of_bits" must be no larger than 8

guint16 tvb_get_bits16(tvbuff_t *tvb, gint bit_offset, gint no_of_bits, gboolean
little_endian)

where "no_of_bits" must be no larger than 16 (and possibly no smaller than 9)

guint32 tvb_get_bits32(tvbuff_t *tvb, gint bit_offset, gint no_of_bits, gboolean
little_endian)

where "no_of_bits" must be no larger than 32 (and possibly no smaller than 17)

guint64 tvb_get_bits64(tvbuff_t *tvb, gint bit_offset, gint no_of_bits, gboolean
little_endian)

		where "no_of_bits" must be no larger than 64

along with proto_tree_add_uint_bits() and proto_tree_add_uint64_bits() routines that take the value to be added, as well as the bit offset and length, as arguments.

That would obviate the need to cast away compiler warnings to get rid of the current buildbot warnings:

packet-umts_fp.c(1873) : error C2220: warning treated as error - no object file generated packet-umts_fp.c(1873) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned char ', possible loss of data packet-umts_fp.c(1882) : warning C4244: '=' : conversion from 'unsigned __int64 ' to 'unsigned short ', possible loss of data

as you'd fetch the value with the appropriate tvb_get_bits() calls and add them with proto_tree_add_uint_bits().

(Should proto_tree_add_bits() be renamed proto_tree_add_item_bits(), to emphasize its kinship with proto_tree_add_item()?)