Skip to content
Permalink
Browse files Browse the repository at this point in the history
Trying to fix some invalid left shift operations
Fixes issue #16
  • Loading branch information
jsummers committed Apr 22, 2017
1 parent 216cb58 commit a001831
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/imagew-bmp.c
Expand Up @@ -425,15 +425,15 @@ static int find_high_bit(unsigned int x)
{
int i;
for(i=31;i>=0;i--) {
if(x&(1<<i)) return i;
if(x&(1U<<(unsigned int)i)) return i;
}
return 0;
}
static int find_low_bit(unsigned int x)
{
int i;
for(i=0;i<=31;i++) {
if(x&(1<<i)) return i;
if(x&(1U<<(unsigned int)i)) return i;
}
return 0;
}
Expand Down
13 changes: 8 additions & 5 deletions src/imagew-util.c
Expand Up @@ -402,27 +402,30 @@ IW_IMPL(void) iw_set_ui32be(iw_byte *b, unsigned int n)

IW_IMPL(unsigned int) iw_get_ui16le(const iw_byte *b)
{
return b[0] | (b[1]<<8);
return (unsigned int)b[0] | ((unsigned int)b[1]<<8);
}

IW_IMPL(unsigned int) iw_get_ui32le(const iw_byte *b)
{
return b[0] | (b[1]<<8) | (b[2]<<16) | (b[3]<<24);
return (unsigned int)b[0] | ((unsigned int)b[1]<<8) |
((unsigned int)b[2]<<16) | ((unsigned int)b[3]<<24);
}

IW_IMPL(int) iw_get_i32le(const iw_byte *b)
{
return (iw_int32)(iw_uint32)(b[0] | (b[1]<<8) | (b[2]<<16) | (b[3]<<24));
return (iw_int32)(iw_uint32)((unsigned int)b[0] | ((unsigned int)b[1]<<8) |
((unsigned int)b[2]<<16) | ((unsigned int)b[3]<<24));
}

IW_IMPL(unsigned int) iw_get_ui16be(const iw_byte *b)
{
return (b[0]<<8) | b[1];
return ((unsigned int)b[0]<<8) | (unsigned int)b[1];
}

IW_IMPL(unsigned int) iw_get_ui32be(const iw_byte *b)
{
return (b[0]<<24) | (b[1]<<16) | (b[2]<<8) | b[3];
return ((unsigned int)b[0]<<24) | ((unsigned int)b[1]<<16) |
((unsigned int)b[2]<<8) | (unsigned int)b[3];
}

// Accepts a flag indicating the endianness.
Expand Down

0 comments on commit a001831

Please sign in to comment.