From: Matias Elo <matias....@nokia.com>

Fix invalid gcc error ('array subscript is above array bounds') when
CONFIG_PACKET_SEGS_PER_HDR is set to one. Tested with gcc 5.4.0.

Signed-off-by: Matias Elo <matias....@nokia.com>
---
/** Email created from pull request 233 (matiaselo:dev/pool_dyn_seg_len)
 ** https://github.com/Linaro/odp/pull/233
 ** Patch: https://github.com/Linaro/odp/pull/233.patch
 ** Base sha: ec0c3145fcafa09ae3a79875e7e07dd4794583cc
 ** Merge commit sha: ada95db815e81074651bb5a5fd0d751fdb17a97c
 **/
 platform/linux-generic/odp_packet.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/platform/linux-generic/odp_packet.c 
b/platform/linux-generic/odp_packet.c
index abd060447..54c986468 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -2151,7 +2151,10 @@ odp_packet_t odp_packet_ref(odp_packet_t pkt, uint32_t 
offset)
        link_hdr->buf_hdr.seg[0].len  = seg->len  - seg_offset;
        buffer_ref_inc(seg->hdr);
 
-       for (i = 1; i < num_copy; i++) {
+       /* The 'CONFIG_PACKET_SEGS_PER_HDR > 1' condition is required to fix an
+        * invalid error ('array subscript is above array bounds') thrown by
+        * gcc (5.4.0). */
+       for (i = 1; CONFIG_PACKET_SEGS_PER_HDR > 1 && i < num_copy; i++) {
                /* Update link header reference count */
                if (idx == 0 && seg_is_link(hdr))
                        buffer_ref_inc((odp_buffer_hdr_t *)hdr);

Reply via email to