format icon indicating copy to clipboard operation
format copied to clipboard

Redundant condition

Open PHackett opened this issue 2 years ago • 3 comments

https://github.com/boostorg/format/blob/78ef371d2d90462671b90c3af407fae07820b193/include/boost/format/alt_sstream_impl.hpp#L127

Line 127 is - else if(way == ::std::ios_base::beg)

It is followed on line 129 - else if(way != ::std::ios_base::beg)

Which, of course is always true given the previous test. This "impossible-redundant-condition" was spotted by a source analyser I used.

PHackett avatar Feb 28 '23 12:02 PHackett

I think the proper solution here is likely the following on lines 129, 130:

                else if(way != ::std::ios_base::cur || (which & ::std::ios_base::in) )
                    // (altering in&out is only supported if way is beg or end, not cur)

Similar to the logic on lines 110, 111:

                else if(way != ::std::ios_base::cur || (which & ::std::ios_base::out) )
                    // (altering in&out is only supported if way is beg or end, not cur)

jeking3 avatar May 15 '24 17:05 jeking3

@PHackett any thoughts on this approach?

jeking3 avatar Jun 04 '24 21:06 jeking3

This was spotted by a static code analyser in an old version of boost - it was fixed in a later version. I suggest that you look at newer versions of the library to see what fix was applied.

PHackett avatar Jun 05 '24 07:06 PHackett