[Boost-bugs] [Boost C++ Libraries] #2825: class boost::detail::atomic_count assumes long == int

Subject: [Boost-bugs] [Boost C++ Libraries] #2825: class boost::detail::atomic_count assumes long == int
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-03-03 22:18:22


#2825: class boost::detail::atomic_count assumes long == int
----------------------------------+-----------------------------------------
 Reporter: pelee_at_[hidden] | Owner: pdimov
     Type: Bugs | Status: new
Milestone: Boost 1.39.0 | Component: smart_ptr
  Version: Boost Release Branch | Severity: Problem
 Keywords: |
----------------------------------+-----------------------------------------
 boost::detail::atomic_count (as defined in atomic_count_gcc_x86.hpp, at
 least), has a member variable value_ that is of type int, yet the class
 constructor and operators use type long. When building for 64 bit targets
 on MacOS 10.5 and other LP64 architectures, long is 64 bits, while int is
 32, leading to silent truncation if a 64 bit value were used to construct
 an atomic_count. Changing all of the signatures to use int instead of long
 solves this problem. It would probably be even safer to replace all the
 ints with boost::int32_t, assuming that the atomic operations being used
 really require 32 bit integers.


 {{{
     explicit atomic_count( int v ) : value_( v ) {}

     void operator++()
     {
         __asm__
         (
             "lock\n\t"
             "incl %0":
             "+m"( value_ ): // output (%0)
             : // inputs
             "cc" // clobbers
         );
     }

     int operator--()
     {
         return atomic_exchange_and_add( &value_, -1 ) - 1;
     }

     operator int() const
     {
         return atomic_exchange_and_add( &value_, 0 );
     }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2825>
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:49:59 UTC