Wireshark-dev: Re: [Wireshark-dev] header field arrays
From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Thu, 18 Jun 2009 16:24:25 -0700

On Jun 18, 2009, at 3:11 PM, Jonathan Walker (c) wrote:

It wasn't giving the specific error, which is why it was so hard to debug.

What non-specific error did it give? Did it crash? If so, could you get a stack trace?

It's not causing me problems anymore though. I made the array into a pointer instead, and allocated the same amount of memory to the pointer, and for some reason it fixed the problem.

I.e. something like:

	static hf_register_info hf[MAX_FIELDS];
	static int hf_ids[MAX_FIELDS];

		...

	for (i = 0; i < cur_field; i++) {
		hf[i].p_id = &hf_ids[i];
		hf[i].hfinfo.name = human-readable name of i'th field;
		hf[i].hfinfo.abbrev = filter name of i'th field;
		hf[i].hfinfo.type = type of i'th field;
		hf[i].hfinfo.display = base (or whatever) of i'th field;
hf[i].hfinfo.strings = true/false strings, or value strings, of i'th field, or NULL;
		hf[i].hfinfo.bitmask = bitmask of i'th field;
		hf[i].hfinfo.blurb = blurb of i'th field;
	}

		...

	proto_register_field_array(proto_shsip, hf, cur_field);

failed, but something like

	static hf_register_info *hf;
	static int hf_ids[MAX_FIELDS];

		...

	hf = g_malloc(MAX_FIELDS*sizeof (hf_register_info);
	for (i = 0; i < cur_field; i++) {
		hf[i].p_id = &hf_ids[i];
		hf[i].hfinfo.name = human-readable name of i'th field;
		hf[i].hfinfo.abbrev = filter name of i'th field;
		hf[i].hfinfo.type = type of i'th field;
		hf[i].hfinfo.display = base (or whatever) of i'th field;
hf[i].hfinfo.strings = true/false strings, or value strings, of i'th field, or NULL;
		hf[i].hfinfo.bitmask = bitmask of i'th field;
		hf[i].hfinfo.blurb = blurb of i'th field;
	}

		...

	proto_register_field_array(proto_shsip, hf, cur_field);

didn't fail?

Note that something like

	static const hf_register_info hf[MAX_FIELDS];

		...

will *NOT* work - you didn't make that array const, did you?