fix left shift of negative value (-fsanitize=undefined)

This commit is contained in:
Artem Pavlenko 2018-02-13 15:14:17 +01:00
parent 15f16ce6ec
commit 3976014dcd

View file

@ -29,6 +29,7 @@ namespace agg
//===================================================dda_line_interpolator //===================================================dda_line_interpolator
template<int FractionShift, int YShift = 0> class dda_line_interpolator template<int FractionShift, int YShift = 0> class dda_line_interpolator
{ {
static constexpr int factor = 2 << (FractionShift - 1);
public: public:
//-------------------------------------------------------------------- //--------------------------------------------------------------------
dda_line_interpolator() {} dda_line_interpolator() {}
@ -36,7 +37,7 @@ namespace agg
//-------------------------------------------------------------------- //--------------------------------------------------------------------
dda_line_interpolator(int y1, int y2, unsigned count) : dda_line_interpolator(int y1, int y2, unsigned count) :
m_y(y1), m_y(y1),
m_inc(((y2 - y1) << FractionShift) / int(count)), m_inc(((y2 - y1) * factor) / static_cast<int>(count)),
m_dy(0) m_dy(0)
{ {
} }
@ -70,7 +71,6 @@ namespace agg
int y() const { return m_y + (m_dy >> (FractionShift - YShift)); } int y() const { return m_y + (m_dy >> (FractionShift - YShift)); }
int dy() const { return m_dy; } int dy() const { return m_dy; }
private: private:
int m_y; int m_y;
int m_inc; int m_inc;