Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH 3/3] Constify two local variables.



On Dec 3, 11:37pm, Daniel Shahaf wrote:
} Subject: Re: [PATCH 3/3] Constify two local variables.
}
} Bart Schaefer wrote on Tue, Dec 01, 2015 at 17:11:21 -0800:
} > On Dec 2, 12:36am, Daniel Shahaf wrote:
} > }
} > }     memcpy(dummy, vals, N)
} > }     setfn(dummy)
} > 
} > Would that memcpy() really work, or would it need to be zarrdup() to copy
} > each of the elements as well?  Because e.g. arrsetfn() does freearray().
} 
} I think it would work, because setarrvalue() in HEAD calls freearray()
} on the values array, implying that the individual elements are already
} permanently allocated.

That's exactly why I think it would NOT work!  If you memcp() only the
pointers and then pass a new pointer-to-pointer into arrsetfn(), it's
going to call freearray() and discard all the individual pointers that
you intended would become the [re-used] elements.



Messages sorted by: Reverse Date, Date, Thread, Author