[Qt-interest] Undefined behavior in QString::toStdWString() ?

Robert Hairgrove evorgriahr at hispeed.ch
Thu Dec 11 16:10:41 CET 2008


Andreas Pakulat wrote:
> On 11.12.08 15:45:58, Robert Hairgrove wrote:
>> [snip] 
>> Isn't this going to cause UDB if str is empty? Because we dereference 
>> the iterator returned from begin() which, like dereferencing end(), is 
>> not allowed.
> 
> Why is dereferencing begin() not allowd? begin() is different from end() as
> it always points to the first element in your collection. end() however
> always points _behind_ the last element, thats why you can't dereference it
> usually.
> 
> Andreas
> 

If str is empty, begin() also does not point to anything, AFAIK; i.e., 
begin() == end() in that case.

It seems to me that checking for length() == 0, which is done only in 
case the compiler is MSVC 2005, should be done in any case.



More information about the Qt-interest-old mailing list