Boost logo

Boost :

From: jarvi (jarvi_at_[hidden])
Date: 2005-08-26 11:08:23


On Aug 25, 2005, at 1:20 PM, Rupert Kittinger wrote:

> Jonathan Wakely wrote:
>> Rupert Kittinger wrote:
>>
>>
>>> In the tuple_io.hpp header, there seems to be a slight problem in
>>> extract_and_check_delimiter(). The following snippet is problematic:
>>>
>>> char c;
>>> if (is_delimiter) {
>>> is >> c;
>>> if (c!=d) {
>>> is.setstate(std::ios::failbit);
>>> }
>>> }
>>>
>>> If c cannot be read because is.eof(), the result of c!=d is
>>> undefined.
>>
>>
>> IMHO the fix is neater as:
>>
>> if (is>>c && c!=d)
>>
>> basic_ios::operator void*() exists to support this syntax rather than
>> explicitly testing the state with good(), fail() etc.
>>
>> jon
>>
>
> Using is.good() is consistent with the rest of the file.
>
> Another fine point that is not visible from the context diff is that
> the
> code works as expected, because the only visible effect of the function
> is the change in stream state. If is >> c failed because of is.eof(),
> the failbit is already set, so it is irrelevant whether the if block is
> executed. But I get false positives from valgrind in my unit tests, and
> in this kind of code, the stack trace looks somewhat confusing :-)
>

I applied the original patch, thanks Rupert!

   Jaakko


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk