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

Message ID 1432904027-6578-2-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_eal/linuxapp/eal/eal_memory.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Neil Horman May 29, 2015, 2:07 p.m. UTC | #1
On Fri, May 29, 2015 at 01:53:44PM +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_eal/linuxapp/eal/eal_memory.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
> index 5f9f92e..744635f 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_memory.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
> @@ -1188,7 +1188,8 @@ rte_eal_hugepage_init(void)
>  		int socket = tmp_hp[i].socket_id;
>  
>  		/* find a hugepage info with right size and increment num_pages */
> -		for (j = 0; j < (int) internal_config.num_hugepage_sizes; j++) {
> +		for (j = 0; j < (int) internal_config.num_hugepage_sizes &&
> +				j < MAX_HUGEPAGE_SIZES; j++) {
>  			if (tmp_hp[i].size ==
Use RTE_MIN here, it will look alot cleaner I think
Neil

>  					internal_config.hugepage_info[j].hugepage_sz) {
>  #ifdef RTE_EAL_SINGLE_FILE_SEGMENTS
> -- 
> 2.4.1
> 
>
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5f9f92e..744635f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1188,7 +1188,8 @@  rte_eal_hugepage_init(void)
 		int socket = tmp_hp[i].socket_id;
 
 		/* find a hugepage info with right size and increment num_pages */
-		for (j = 0; j < (int) internal_config.num_hugepage_sizes; j++) {
+		for (j = 0; j < (int) internal_config.num_hugepage_sizes &&
+				j < MAX_HUGEPAGE_SIZES; j++) {
 			if (tmp_hp[i].size ==
 					internal_config.hugepage_info[j].hugepage_sz) {
 #ifdef RTE_EAL_SINGLE_FILE_SEGMENTS