Le 12/22/2016 à 02:49 PM, Maxim Uvarov a écrit :
> On debian jessie gcc unable to compile current code
> with error:
> odp_packet.c: In function 'odp_packet_trunc_head':
> odp_packet.c:314:46: error: array subscript is above array bounds 
> [-Werror=array-bounds]
> to->buf_hdr.seg[i].len = from->buf_hdr.seg[num + i].len;
>
> The problem is that it breaks compilation only on .len line:
> for (i = 0; i < num; i++) {
>       to->buf_hdr.seg[i].hdr  = from->buf_hdr.seg[num + i].hdr;
>       to->buf_hdr.seg[i].data = from->buf_hdr.seg[num + i].data;
>       to->buf_hdr.seg[i].len  = from->buf_hdr.seg[num + i].len;
> }
>
> If that line is commented out compilation passes. If lines are reordered
> than compilation also fails on .len line. Because there is no warning on
> .hdr and .data it looks like compiler error. Additional check for
> preconfigured value is workaround to that situation.
>
> Signed-off-by: Maxim Uvarov <maxim.uva...@linaro.org>
> ---
>  v2: - add comment (Mike)
>      - in description .len line reorder does not fix compilation (Bill)
>
>  platform/linux-generic/odp_packet.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/platform/linux-generic/odp_packet.c 
> b/platform/linux-generic/odp_packet.c
> index 0d3fd05..599d839 100644
> --- a/platform/linux-generic/odp_packet.c
> +++ b/platform/linux-generic/odp_packet.c
> @@ -309,6 +309,10 @@ static inline void copy_num_segs(odp_packet_hdr_t *to, 
> odp_packet_hdr_t *from,
>       int i;
>  
>       for (i = 0; i < num; i++) {
> +             /* check bellow also fixes gcc bug, refer to corresponding
> +              * git commit */
> +             if (odp_unlikely((num + i) >= CONFIG_PACKET_MAX_SEGS))
> +                     ODP_ABORT("packet segmenation error\n");
There's a typo in segmentation

>               to->buf_hdr.seg[i].hdr  = from->buf_hdr.seg[num + i].hdr;
>               to->buf_hdr.seg[i].data = from->buf_hdr.seg[num + i].data;
>               to->buf_hdr.seg[i].len  = from->buf_hdr.seg[num + i].len;

Reply via email to