Skip to content

Commit

Permalink
Fix crash in raster calculator on Windows builds
Browse files Browse the repository at this point in the history
It's not safe to take the data from a vector like this, it will be
deleted as soon as the vector itself is

Fixes #32855

(cherry picked from commit e3d2dcd)
  • Loading branch information
nyalldawson authored and nirvn committed Nov 26, 2019
1 parent 6d9fe0b commit 3af8993
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/analysis/raster/qgsrastercalcnode.cpp
Expand Up @@ -60,6 +60,7 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterBlock * > &rasterData,
QMap<QString, QgsRasterBlock *>::iterator it = rasterData.find( mRasterName );
if ( it == rasterData.end() )
{
QgsDebugMsg( QStringLiteral( "Error: could not find raster data for \"%1\"" ).arg( mRasterName ) );
return false;
}

Expand Down Expand Up @@ -190,9 +191,10 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterBlock * > &rasterData,
else if ( mType == tNumber )
{
size_t nEntries = static_cast<size_t>( result.nColumns() * result.nRows() );
std::vector<double> *data = new std::vector<double>( nEntries );
std::fill( std::begin( *data ), std::end( *data ), mNumber );
result.setData( result.nColumns(), 1, data->data(), result.nodataValue() );
double *data = new double[ nEntries ];
std::fill( data, data + nEntries, mNumber );
result.setData( result.nColumns(), 1, data, result.nodataValue() );

return true;
}
else if ( mType == tMatrix )
Expand Down

0 comments on commit 3af8993

Please sign in to comment.