Skip to content

fix: Wrong return type of copy_fn and missing typedef in destruct_range #708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions include/boost/gil/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,24 @@ namespace std {
template<typename T, typename CS>
BOOST_FORCEINLINE
auto copy(
boost::gil::pixel<T, CS>* first,
boost::gil::pixel<T, CS>* last,
boost::gil::pixel<T, CS> const* first,
boost::gil::pixel<T, CS> const* last,
boost::gil::pixel<T, CS>* dst)
-> boost::gil::pixel<T, CS>*
{
auto p = std::copy((unsigned char*)first, (unsigned char*)last, (unsigned char*)dst);
auto p = std::copy(
reinterpret_cast<unsigned char const*>(first),
reinterpret_cast<unsigned char const*>(last),
reinterpret_cast<unsigned char*>(dst));
return reinterpret_cast<boost::gil::pixel<T, CS>*>(p);
}

/// \ingroup STLOptimizations
/// \brief Copy when both src and dst are interleaved and of the same type can be just memmove
template<typename T, typename CS>
BOOST_FORCEINLINE
auto copy(const boost::gil::pixel<T,CS>* first, const boost::gil::pixel<T,CS>* last,
boost::gil::pixel<T,CS>* dst) -> boost::gil::pixel<T,CS>*
{
return (boost::gil::pixel<T,CS>*)std::copy((unsigned char*)first,(unsigned char*)last, (unsigned char*)dst);
}
} // namespace std

namespace boost { namespace gil {
namespace detail {
template <typename I, typename O> struct copy_fn {
BOOST_FORCEINLINE I operator()(I first, I last, O dst) const { return std::copy(first,last,dst); }
BOOST_FORCEINLINE O operator()(I first, I last, O dst) const { return std::copy(first,last,dst); }
Comment on lines -169 to +163
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, amazing it remained unrevealed for long time.
How did you find it out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, amazing it remained unrevealed for long time.

I was also surprised after realizing this bug has been there for at least 15 years. I guess the reason is copy_fn is not used in many places and as long as the output iterator is implicitly convertible to the input iterator (as it is the case for pointers which only differ in their const-qualifier), everything is fine.

How did you find it out?

Just me, the algorithm header and a cup of coffee.

};
} // namespace detail
} } // namespace boost::gil
Expand Down Expand Up @@ -454,8 +448,9 @@ void destruct_range_impl(Iterator first, Iterator last,
detail::is_trivially_destructible<typename std::iterator_traits<Iterator>::value_type>
>
>::value
>::type* /*ptr*/ = 0)
>::type* /* ptr */ = nullptr)
{
using value_t = typename std::iterator_traits<Iterator>::value_type;
while (first != last)
{
first->~value_t();
Expand Down