This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [libstdc++ patch] Fix basic_string::_S_construct null pointer check


On Mon, Jul 14, 2003 at 11:48:20AM -0700, Doug Gregor wrote:
> basic_string::_S_construct attempts to do a null-pointer check by 
> comparing the "__beg" iterator to a default-constructed iterator of the 
> same type. This both triggers an error in debug mode ("attempt to 
> compare against a singular iterator") and could cause incorrect 
> behavior in release mode in the following unlikely circumstance:
> 
> 	1) [begin, end) is an empty iterator range, and
> 	2) end is equal to a default-constructed iterator, and
> 	3) the user passes in an allocator that is not equivalent to a 
> default-constructed allocator

It's not so unlikely, in fact.  A reverse_itertor<char*> evokes
the failure mode.

This looks like an elegant way to fix the problem while retaining
the ability to detect the common case of a null pointer.

Nathan Myers
ncm-nospam@cantrip.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]