char_traits

Nathan Myers ncm@cantrip.org
Fri Apr 28 14:08:00 GMT 2000


Most of Vadim's changes are good.  However, a few, noted below,
are not right.  

The problems are in the potential to invoke undefined behavior.  
In particular, comparing a pointer against (__s + __n) is not 
appropriate in a find() function, because that pointer value might 
not exist.  (This approach is OK in copy() functions because all 
the characters from __s to __s+__n will be examined anyway.)  The 
alternative is to cast size_t(__p-__s) before comparing to __n.

On Fri, Apr 28, 2000 at 08:01:39PM +0400, Vadim Egorov wrote:
> Here is a patch which fixes parameter types for char_traits<> 
> -- nearly all size_t's are currently int_type's. 
> diff -c -r1.28 char_traits.h
> ! 	for (const char_type* __p = __s; __p < __s +__n; ++__p)

Nathan Myers
ncm at cantrip dot org


More information about the Libstdc++ mailing list