mirror of
https://github.com/boostorg/gil.git
synced 2026-02-18 02:02:09 +00:00
Fix UB due to overflowing bit-shift operation (#68)
Patch courtesy of Andrey Semashev via Boost ML.
This commit is contained in:
committed by
Stefan Seefeld
parent
f7d83feb83
commit
b6174343af
@@ -329,7 +329,7 @@ template <> struct channel_convert_to_unsigned<bits16s> : public std::unary_func
|
||||
|
||||
template <> struct channel_convert_to_unsigned<bits32s> : public std::unary_function<bits32s,bits32> {
|
||||
typedef bits32 type;
|
||||
type operator()(bits32s x) const { return static_cast<bits32>(x+(1<<31)); }
|
||||
type operator()(bits32s x) const { return static_cast<bits32>(x)+(1u<<31); }
|
||||
};
|
||||
|
||||
|
||||
@@ -352,7 +352,7 @@ template <> struct channel_convert_from_unsigned<bits16s> : public std::unary_fu
|
||||
|
||||
template <> struct channel_convert_from_unsigned<bits32s> : public std::unary_function<bits32,bits32s> {
|
||||
typedef bits32s type;
|
||||
type operator()(bits32 x) const { return static_cast<bits32s>(x-(1<<31)); }
|
||||
type operator()(bits32 x) const { return static_cast<bits32s>(x-(1u<<31)); }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -189,7 +189,7 @@ public:
|
||||
|
||||
if( entries == 0 )
|
||||
{
|
||||
entries = 1 << this->_info._bits_per_pixel;
|
||||
entries = 1u << this->_info._bits_per_pixel;
|
||||
}
|
||||
|
||||
_palette.resize( entries, rgba8_pixel_t(0, 0, 0, 0));
|
||||
|
||||
@@ -289,7 +289,7 @@ private:
|
||||
|
||||
if( entries == 0 )
|
||||
{
|
||||
entries = 1 << this->_info._bits_per_pixel;
|
||||
entries = 1u << this->_info._bits_per_pixel;
|
||||
}
|
||||
|
||||
this->_palette.resize( entries, rgba8_pixel_t(0,0,0,0) );
|
||||
|
||||
@@ -111,7 +111,7 @@ private:
|
||||
/// in this context.
|
||||
if( bpp <= 8 )
|
||||
{
|
||||
entries = 1 << bpp;
|
||||
entries = 1u << bpp;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ protected:
|
||||
|
||||
if( _info._valid_transparency_factors )
|
||||
{
|
||||
int sample_max = ( 1 << _info._bit_depth );
|
||||
int sample_max = ( 1u << _info._bit_depth );
|
||||
|
||||
/* libpng doesn't reject a tRNS chunk with out-of-range samples */
|
||||
if( !( ( _info._color_type == PNG_COLOR_TYPE_GRAY
|
||||
|
||||
Reference in New Issue
Block a user