Opened 20 years ago

Closed 19 years ago

#109 closed Bugs (Rejected)

counted_base::add_ref not overflow-safe

Reported by: nobody Owned by: nobody
Milestone: Component: smart_ptr
Version: None Severity:
Keywords: Cc:

Description

Greetings,

In order to track the number of shared_ptrs that refer to 
a certain object, the function counted_base::add_ref 
calls the overloaded operator ++() of the corresponding 
count_type member data. That in turn does increment a 
variable of built-in type (volatile long), but it does not 
check wether the result fits into the variable or not.

A possible solution:

a) in atomic_count::operator ++():
    if(value_ != std::numeric_limits<volatile long>::max())
          ...call atomic increment
    else
        throw ... some exception


b) at least mention this somewhere in the 
documentation.


Although this is certainly a situation unlikely to be ever 
appearing in practice, it might happen and can be the 
source for lots of trouble.


best regards,

Thomas Mang


Change History (2)

comment:1 by shammah, 20 years ago

Logged In: YES 
user_id=146506

"unlikely" is right; this would require 
std::numeric_limits<long>::max() smart pointer objects.

I do not think that this constitutes a change to the code.

comment:2 by Peter Dimov, 19 years ago

Status: assignedclosed
Note: See TracTickets for help on using tickets.