|
From: Daniel J S. <dan...@ie...> - 2007-06-30 19:56:43
|
Daniel J Sebald wrote:
> if (!this->v)
> graph_error("resize_dynarray: dynarray wasn't initialized!");
>
[snip]
> It will save a test every time nextfrom_dynarray() is called (which
> is fairly considerable). Plus, let's say init_dynarray *wasn't*
> called. gp_alloc uses "malloc" which isn't guaranteed to be zero
> (probably system dependent). gnuplot should be using "calloc" if the
> above test is to be foolproof.
Allow me to clarify. The above test assumes that the dynarray structure pointed to by "this" was initialized to zero. I'm not sure how one guarantees that the programmer had done so or that a previously used dynarray structure was reset to zero. (In the case I'm looking at memset() is already used to initialize the whole plot_struct so it's fine.) Also, if dynarray is modified to guaranteed that the above test is foolproof, then it should be possible in init_dynarray to also test on this->v to ensure that init_dynarray isn't leaking memory with
this->v = 0; /* preset value, in case gp_alloc fails */
So, in summary, the above test isn't foolproof but it is only for the programmer's benefit and shouldn't cause a bug on systems that don't zero malloc memory, provided gnuplot was programmed correctly. Could we change to
if (!this->entry_size)
graph_error("resize_dynarray: dynarray wasn't initialized!");
instead?
Dan
|