[PATCH] cliptest: Don't underrun the vertex array of empty polygons.
Ondrej Majerech
oxyd.oxyd at gmail.com
Tue Aug 19 05:24:14 PDT 2014
On 19 August 2014 14:16, Pekka Paalanen <ppaalanen at gmail.com> wrote:
> On Tue, 19 Aug 2014 13:10:55 +0200
> Ondřej Majerech <oxyd.oxyd at gmail.com> wrote:
>
>> This silences the following warning:
>>
>> clients/cliptest.c:277:22: warning: array subscript is below array
>> bounds [-Warray-bounds]
>> ctx->prev.x = src->x[src->n - 1];
>
> Hi,
>
> seems like I would need something more recent than gcc 4.6.4 to get
> these warnings, right?
I'm using GCC 4.9.1, so presumably yes. :)
>
> Do you not get these warnings from src/vertex-clipping.c too?
Ah, yes. Fresh rebuild gives me warnings from src/vertex-clipping.c as well.
>
> At minimum, could you patch both clients/cliptest.c and
> src/vertex-clipping.c in the same patch, and check that the duplicated
> code is identical.
>
> An even better alternative would be to just drop the duplicate code
> from cliptest.c, and make it somehow just use src/vertex-clipping.c
> and .h. I'm not sure how the build system would cope with that, but
> that would be excellent. So first remove duplication, then fix the
> issues.
indeed. I'll see what I can do about the duplication.
>
> Also, I think the correct condition would be:
> if (src->n < 2)
> return 0;
>
> Because if a polygon has less than 2 points, it's not a polygon that
> could even theoretically be clipped. The 2 points case also is
> denegerate, but least it has two lines that can be clipped.
You're right -- I was thinking more about buffers than geometry. :)
>
>
> Thanks,
> pq
>
>>
>> Signed-off-by: Ondřej Majerech <oxyd.oxyd at gmail.com>
>> ---
>> clients/cliptest.c | 12 ++++++++++++
>> 1 file changed, 12 insertions(+)
>>
>> diff --git a/clients/cliptest.c b/clients/cliptest.c
>> index 907c5d4..20b3776 100644
>> --- a/clients/cliptest.c
>> +++ b/clients/cliptest.c
>> @@ -287,6 +287,9 @@ clip_polygon_left(struct clip_context *ctx, const struct polygon8 *src,
>> enum path_transition trans;
>> int i;
>>
>> + if (src->n == 0)
>> + return 0;
>> +
>> clip_context_prepare(ctx, src, dst_x, dst_y);
>> for (i = 0; i < src->n; i++) {
>> trans = path_transition_left_edge(ctx, src->x[i], src->y[i]);
>> @@ -303,6 +306,9 @@ clip_polygon_right(struct clip_context *ctx, const struct polygon8 *src,
>> enum path_transition trans;
>> int i;
>>
>> + if (src->n == 0)
>> + return 0;
>> +
>> clip_context_prepare(ctx, src, dst_x, dst_y);
>> for (i = 0; i < src->n; i++) {
>> trans = path_transition_right_edge(ctx, src->x[i], src->y[i]);
>> @@ -319,6 +325,9 @@ clip_polygon_top(struct clip_context *ctx, const struct polygon8 *src,
>> enum path_transition trans;
>> int i;
>>
>> + if (src->n == 0)
>> + return 0;
>> +
>> clip_context_prepare(ctx, src, dst_x, dst_y);
>> for (i = 0; i < src->n; i++) {
>> trans = path_transition_top_edge(ctx, src->x[i], src->y[i]);
>> @@ -335,6 +344,9 @@ clip_polygon_bottom(struct clip_context *ctx, const struct polygon8 *src,
>> enum path_transition trans;
>> int i;
>>
>> + if (src->n == 0)
>> + return 0;
>> +
>> clip_context_prepare(ctx, src, dst_x, dst_y);
>> for (i = 0; i < src->n; i++) {
>> trans = path_transition_bottom_edge(ctx, src->x[i], src->y[i]);
>
More information about the wayland-devel
mailing list