Skip to content

Commit

Permalink
Use better approach for malloc size safety (logic ported from GDAL)
Browse files Browse the repository at this point in the history
Fixes #47097
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Feb 1, 2022
1 parent ac9fd15 commit 0021306
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/core/qgis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,18 @@ qlonglong qgsPermissiveToLongLong( QString string, bool &ok )

void *qgsMalloc( size_t size )
{
if ( size == 0 || long( size ) < 0 )
if ( size == 0 )
{
QgsDebugMsg( QStringLiteral( "Negative or zero size %1." ).arg( size ) );
QgsDebugMsg( QStringLiteral( "Zero size requested" ) );
return nullptr;
}

if ( ( size >> ( 8 * sizeof( size ) - 1 ) ) != 0 )
{
QgsDebugMsg( QStringLiteral( "qgsMalloc - bad size requested: %1" ).arg( size ) );
return nullptr;
}

void *p = malloc( size );
if ( !p )
{
Expand Down

0 comments on commit 0021306

Please sign in to comment.