boostorg / format

Boost.org format module
http://boost.org/libs/format
Boost Software License 1.0
25 stars 51 forks source link

Redundant condition #93

Open PHackett opened 1 year ago

PHackett commented 1 year ago

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.

jeking3 commented 5 months ago

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 commented 5 months ago

@PHackett any thoughts on this approach?

PHackett commented 5 months ago

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.