Menu

#204 hashtable::resize bug in STLport5.2.1

5.2
open-rejected
5
2009-04-07
2009-03-27
stsoe
No

The function (in _hashtable.c)
template <class _Val, class _Key, class _HF,
class _Traits, class _ExK, class _EqK, class _All>
void hashtable<_Val,_Key,_HF,_Traits,_ExK,_EqK,_All>
::rehash(size_type __num_buckets_hint)

used to call _Stl_prime_type::_S_next_size(__num_buckets_hint) before doing an actual rehash. In 5.2.1 the call to S_next_size has been removed and the actual rehash in called directly with the 'hint' value supplied by the user via resize(). This leads to an exception if the user supplied the value '0' for the hint.

Thanks,
Soren Soe.

Discussion

  • Petr Ovtchenkov

    Petr Ovtchenkov - 2009-03-30
    • assigned_to: nobody --> complement
     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2009-03-30

    Looks like marginal usage. Do you have sample code that illustrate potential problem?

     
  • stsoe

    stsoe - 2009-03-30

    Yes probably marginal, but I imagine this could happen after populating a hash, then shrinking it based on how many elements actually inserted. For the particular case I ran into, no elements are in the hash map at the time resize is called. Resize actually works, but the following find() causes a crash because bucket_count() is 0.

    How about this small example:
    #include <hash_map>
    int main()
    {
    std::hash_map<int,int> hm;
    hm.resize(0);
    hm.find(0);
    return 0;
    }

    Thanks,
    Soren

     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2009-04-07

    As hm.resize(0) as hm.rehash(0) are bad usage, nonsense from algorithm point of view.

    jtc1/sc22/wg21 treat issues of such kind as NAD (not a defect), but it may be issue for debug library variant. Compare with:

    strlen( 0 );

    or

    strlen( 0x2 );

     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2009-04-07
    • status: open --> open-rejected
     

Log in to post a comment.