[dpdk-dev,2/4] ip_frag: fix compile on Fedora 22 (GCC 5.1)

Message ID 1432904027-6578-3-git-send-email-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Bruce Richardson May 29, 2015, 12:53 p.m. UTC
  On Fedora 22, with GCC 5.1, errors are reported due to array accesses
being potentially out of bounds. This commit fixes this by adding in an
extra bounds check to the loop counter.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_ip_frag/ip_frag_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Neil Horman May 29, 2015, 2:09 p.m. UTC | #1
On Fri, May 29, 2015 at 01:53:45PM +0100, Bruce Richardson wrote:
> On Fedora 22, with GCC 5.1, errors are reported due to array accesses
> being potentially out of bounds. This commit fixes this by adding in an
> extra bounds check to the loop counter.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  lib/librte_ip_frag/ip_frag_common.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_ip_frag/ip_frag_common.h b/lib/librte_ip_frag/ip_frag_common.h
> index 210f409..e37073b 100644
> --- a/lib/librte_ip_frag/ip_frag_common.h
> +++ b/lib/librte_ip_frag/ip_frag_common.h
> @@ -90,7 +90,7 @@ static inline int
>  ip_frag_key_is_empty(const struct ip_frag_key * key)
>  {
>  	uint32_t i;
> -	for (i = 0; i < key->key_len; i++)
> +	for (i = 0; i < key->key_len && i < RTE_DIM(key->src_dst); i++)
>  		if (key->src_dst[i] != 0)
>  			return 0;
>  	return 1;
> -- 
> 2.4.1
> 
> 
RTE_MIN again
Neil
  

Patch

diff --git a/lib/librte_ip_frag/ip_frag_common.h b/lib/librte_ip_frag/ip_frag_common.h
index 210f409..e37073b 100644
--- a/lib/librte_ip_frag/ip_frag_common.h
+++ b/lib/librte_ip_frag/ip_frag_common.h
@@ -90,7 +90,7 @@  static inline int
 ip_frag_key_is_empty(const struct ip_frag_key * key)
 {
 	uint32_t i;
-	for (i = 0; i < key->key_len; i++)
+	for (i = 0; i < key->key_len && i < RTE_DIM(key->src_dst); i++)
 		if (key->src_dst[i] != 0)
 			return 0;
 	return 1;