diff mbox series

Fix -Wshadow=local warnings in hash-table.h

Message ID VI1PR03MB45287EC15BC0E4D31FF4824CE49F0@VI1PR03MB4528.eurprd03.prod.outlook.com
State New
Headers show
Series Fix -Wshadow=local warnings in hash-table.h | expand

Commit Message

Bernd Edlinger Oct. 3, 2019, 3:18 p.m. UTC
Hi,

this fixes a few -Wshadow=local warnings in hash-table.h.

Since values of type size_t are assigned here to int variables
an overflow may happen resulting in memory leaks or malfunction.


Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.

Comments

Richard Sandiford Oct. 4, 2019, 12:06 p.m. UTC | #1
Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
> Hi,
>
> this fixes a few -Wshadow=local warnings in hash-table.h.
>
> Since values of type size_t are assigned here to int variables
> an overflow may happen resulting in memory leaks or malfunction.
>
>
> Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
> Is it OK for trunk?
>
>
> Thanks
> Bernd.
>
> 2019-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>
>
> 	* hash-table.h (hash_table::empty_slow): Don't assign
> 	size_t values to int variables.

OK, thanks.

Richard

> Index: gcc/hash-table.h
> ===================================================================
> --- gcc/hash-table.h	(revision 276484)
> +++ gcc/hash-table.h	(working copy)
> @@ -842,9 +842,8 @@ hash_table<Descriptor, Lazy, Allocator>::empty_slo
>    size_t size = m_size;
>    size_t nsize = size;
>    value_type *entries = m_entries;
> -  int i;
>  
> -  for (i = size - 1; i >= 0; i--)
> +  for (size_t i = size - 1; i < size; i--)
>      if (!is_empty (entries[i]) && !is_deleted (entries[i]))
>        Descriptor::remove (entries[i]);
>  
> @@ -856,9 +855,10 @@ hash_table<Descriptor, Lazy, Allocator>::empty_slo
>  
>    if (nsize != size)
>      {
> -      int nindex = hash_table_higher_prime_index (nsize);
> -      int nsize = prime_tab[nindex].prime;
> +      unsigned int nindex = hash_table_higher_prime_index (nsize);
>  
> +      nsize = prime_tab[nindex].prime;
> +
>        if (!m_ggc)
>  	Allocator <value_type> ::data_free (m_entries);
>        else
diff mbox series

Patch

2019-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* hash-table.h (hash_table::empty_slow): Don't assign
	size_t values to int variables.

Index: gcc/hash-table.h
===================================================================
--- gcc/hash-table.h	(revision 276484)
+++ gcc/hash-table.h	(working copy)
@@ -842,9 +842,8 @@  hash_table<Descriptor, Lazy, Allocator>::empty_slo
   size_t size = m_size;
   size_t nsize = size;
   value_type *entries = m_entries;
-  int i;
 
-  for (i = size - 1; i >= 0; i--)
+  for (size_t i = size - 1; i < size; i--)
     if (!is_empty (entries[i]) && !is_deleted (entries[i]))
       Descriptor::remove (entries[i]);
 
@@ -856,9 +855,10 @@  hash_table<Descriptor, Lazy, Allocator>::empty_slo
 
   if (nsize != size)
     {
-      int nindex = hash_table_higher_prime_index (nsize);
-      int nsize = prime_tab[nindex].prime;
+      unsigned int nindex = hash_table_higher_prime_index (nsize);
 
+      nsize = prime_tab[nindex].prime;
+
       if (!m_ggc)
 	Allocator <value_type> ::data_free (m_entries);
       else