Skip to content

Commit

Permalink
Check for negative numbers (and zero) before casting in ogrlibkmlfeat…
Browse files Browse the repository at this point in the history
…ure.cpp:IsPowerOf2().

Coverity - Overflowed return value.

2. overflow: Subtract operation overflows on operands nTmp and 1U.
   	     
CID 164965 (#1 of 1): Overflowed return value (INTEGER_OVERFLOW)

3. overflow_sink: Overflowed or truncated value (or a value computed from an
overflowed or truncated value) nTmp != 0U && (nTmp & nTmp - 1U) == 0U used as
return value.


git-svn-id: https://svn.osgeo.org/gdal/trunk@34758 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
schwehr committed Jul 22, 2016
1 parent 9b4cfdd commit e7fbe69
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions gdal/ogr/ogrsf_frmts/libkml/ogrlibkmlfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ static CPLString OGRLIBKMLReplaceLevelXYInURL( const char* pszURL,

static bool IsPowerOf2( int nVal )
{
if( nVal < 1 ) return false;

const unsigned int nTmp = static_cast<unsigned int>(nVal);

return
nTmp != 0 &&
(nTmp & (nTmp - 1)) == 0;
return (nTmp & (nTmp - 1)) == 0;
}

/************************************************************************/
Expand Down

0 comments on commit e7fbe69

Please sign in to comment.