Wireshark-dev: Re: [Wireshark-dev] header field arrays
From: "Jonathan Walker (c)" <JWalker@xxxxxxxxxxxx>
Date: Fri, 19 Jun 2009 07:29:56 -0700
Yeah, the program just crashed.  It said it was a runtime error and was forced to close unexpectedly or something.

And yes, those examples are very similar to what I had and the only change I made was what you changed, changing the array into a pointer and allocating memory to it with calloc( ), and for some reason the crash went away.

Maybe has something to do with how memory is allocated for arrays?  I don't know.

-----Original Message-----
From: wireshark-dev-bounces@xxxxxxxxxxxxx [mailto:wireshark-dev-bounces@xxxxxxxxxxxxx] On Behalf Of Guy Harris
Sent: Thursday, June 18, 2009 6:24 PM
To: Developer support list for Wireshark
Subject: Re: [Wireshark-dev] header field arrays


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?
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe