[Boost-bugs] [Boost C++ Libraries] #7739: Divide by zero error in hash_map.hpp

Subject: [Boost-bugs] [Boost C++ Libraries] #7739: Divide by zero error in hash_map.hpp
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-11-27 04:10:11


#7739: Divide by zero error in hash_map.hpp
------------------------------------------------+---------------------------
 Reporter: Gaurav Gupta <g.gupta@…> | Owner: chris_kohlhoff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.52.0 | Severity: Problem
 Keywords: |
------------------------------------------------+---------------------------
 In the code snippet, while doing '''calculate_hash_value(iter->first) %
 num_buckets_'''
 If value of '''num_buckets_ is 0''', then it leads to Divide By zero
 error.

 void rehash(std::size_t num_buckets)
   {
     if (num_buckets == num_buckets_)
       return;
     num_buckets_ = num_buckets;

     iterator end_iter = values_.end();

     ----- SOME CODE ------------

     // Put all values back into the hash.
     iterator iter = values_.begin();
     while (iter != end_iter)
     {
       '''std::size_t bucket = calculate_hash_value(iter->first) %
 num_buckets_;'''

 if (buckets_[bucket].last == end_iter)
       {
         buckets_[bucket].first = buckets_[bucket].last = iter++;
       }
      ------- SOME CODE -----------

 Attached patch is the fix for it.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7739>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC