[cairo] [cairo-commit] 3 commits - src/cairo-array.c src/cairoint.h src/cairo-types-private.h
Bill Spitzak
spitzak at gmail.com
Sun Nov 28 13:59:43 PST 2010
On 11/28/2010 12:08 AM, Andrea Canciani wrote:
> On Sun, Nov 28, 2010 at 4:36 AM, Bill Spitzak<spitzak at gmail.com> wrote:
>> This code in the comment makes no sense to me:
>>
>>>>>> + /* We allow an index of 0 for the no-elements case.
>>>>>> + * This makes for cleaner calling code which will often look like:
>>>>>> + *
>>>>>> + * elements = _cairo_array_index_const (array, num_elements);
>>>>>> + * for (i=0; i< num_elements; i++) {
>>>>>> + * ... read elements[i] here ...
>>>>>> + * }
>>>>>> + *
>>>>>> + * which in the num_elements==0 case gets the NULL pointer here,
>>>>>> + * but never dereferences it.
>>>>>> + */
>>
>
> + * elements = _cairo_array_index_const (array, num_elements);
> should be
> + * elements = _cairo_array_index_const (array, 0);
>
> (same for the comment in _cairo_array_index)
>
> Andrea
That helps, but it still seems to require that zero not be treated
specially.
I'm guessing that the user wants a pointer to the first of the range N
.. N+num_elements (and knows for other reasons that this is not outside
the array bounds).
However if num_elements is zero, this must not throw for the size of the
array, as there is in fact a valid zero-length array at that point.
Therefore it seems this function must never throw for n==size if this is
to work.
If in fact this is never done except with zero, I would make a
*different* call, perhaps called "cairo_array_get_array", that never
throws and just returns the pointer to the array.
More information about the cairo
mailing list