Opened 20 years ago
Closed 20 years ago
#676 closed defect (fixed)
psArrayAlloc()'s semantics are error prone
| Reported by: | jhoblitt | Owned by: | Paul Price |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | PSLib SDRS | Version: | unspecified |
| Severity: | major | Keywords: | |
| Cc: | robert.desonia@… |
Description
As currently defined in the SDRS psArrayAlloc() set's the index to the last
element in the array, "the value of \code{psArray.n} is
set to \code{nalloc}". To be of just about any practical use the programmer has
to manually reset the index to 0 before attempting to populate the array. This
issue is exacerbated by the fact that array elements are left uninialized so
failure to reset the index leaves garbage pointers at the beginning of the array.
I propose two changes:
a) the index of newly created arrays is always 0
b) all 'new' elements of created or resized arrays are initialized to NULL

(a) Agreed, but this also applies to vectors.
In these functions, \code{nalloc} is the number of elements to
allocate. In \code{psArrayAlloc}, the value of \code{psArray.n} is
initially set to zero.
In these functions, \code{nalloc} is the number of elements to
allocate. For \code{psVectorAlloc}, the value of \code{psVector.n} is
initially set to zero.
(b) Agreed.
Since \code{psArray} stores pointers, values on the array shall always
be initialised to \code{NULL} on \code{psArrayAlloc}.
\code{psArrayRealloc} shall initialise values to \code{NULL} where the
array has been grown.
Updated the SDRS. I will create a bug on pslib to track this issue (bug 682).