Re: [Boost-bugs] [Boost C++ Libraries] #2200: Bad memory management in algorithm::is_any_of

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2200: Bad memory management in algorithm::is_any_of
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-08-21 11:46:43

#2200: Bad memory management in algorithm::is_any_of
  Reporter: jgottman_at_[hidden] | Owner: pavol_droba
      Type: Bugs | Status: closed
 Milestone: To Be Determined | Component: string_algo
   Version: Boost 1.35.0 | Severity: Problem
Resolution: fixed | Keywords: string algorithms

Comment(by Joe Gottman <jgottman_at_[hidden]>):

 This doesn't fix the self-assignment problem. If we have code like
    is_any_of<char> foo("abcdefghijklmnopqrstuvwxyz");
    foo = foo;

    then the operator= as currently written will delete
 this->m_Storage.m_dynSet (which is the same thing as
 Other.m_Storage.m_dynSet), and replace it with garbage. There are two
 possible ways to fix this. The first is to put the following code at the
 beginning of operator=
     if (this == &Other) return *this;

    The second is to do the following: If *this and Other both allocate
 memory, check whether Other->m_Size is less than or equal to this->m_Size.
 If it is, then we don't have to reallocate this->m_Storage.m_dynSet. It
 will already have enough space allocated to hold the string from Other.
 It might have more space allocated than necessary, but that is no big
 deal. This saves us an unnecessary reallocation in some cases, including
 the self-assignment case.

Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC