Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a8d25d6

Browse files
nyalldawsongithub-actions[bot]
authored andcommittedMar 3, 2023
Fix some potential overflows in shapeburst fill calculation
1 parent 17b73cd commit a8d25d6

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed
 

‎src/core/symbology/qgsfillsymbollayer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,11 +1453,11 @@ void QgsShapeburstFillSymbolLayer::distanceTransform1d( double *f, int n, int *v
14531453
z[1] = + INF;
14541454
for ( int q = 1; q <= n - 1; q++ )
14551455
{
1456-
double s = ( ( f[q] + q * q ) - ( f[v[k]] + ( v[k] * v[k] ) ) ) / ( 2 * q - 2 * v[k] );
1456+
double s = ( ( f[q] + static_cast< double >( q ) * q ) - ( f[v[k]] + ( static_cast< double >( v[k] ) * v[k] ) ) ) / ( 2 * q - 2 * v[k] );
14571457
while ( s <= z[k] )
14581458
{
14591459
k--;
1460-
s = ( ( f[q] + q * q ) - ( f[v[k]] + ( v[k] * v[k] ) ) ) / ( 2 * q - 2 * v[k] );
1460+
s = ( ( f[q] + static_cast< double >( q ) * q ) - ( f[v[k]] + ( static_cast< double >( v[k] ) * v[k] ) ) ) / ( 2 * q - 2 * v[k] );
14611461
}
14621462
k++;
14631463
v[k] = q;
@@ -1470,7 +1470,7 @@ void QgsShapeburstFillSymbolLayer::distanceTransform1d( double *f, int n, int *v
14701470
{
14711471
while ( z[k + 1] < q )
14721472
k++;
1473-
d[q] = ( q - v[k] ) * ( q - v[k] ) + f[v[k]];
1473+
d[q] = static_cast< double >( q - v[k] ) * ( q - v[k] ) + f[v[k]];
14741474
}
14751475
}
14761476

@@ -1491,12 +1491,12 @@ void QgsShapeburstFillSymbolLayer::distanceTransform2d( double *im, int width, i
14911491

14921492
for ( int y = 0; y < height; y++ )
14931493
{
1494-
f[y] = im[ x + y * width ];
1494+
f[y] = im[ x + static_cast< std::size_t>( y ) * width ];
14951495
}
14961496
distanceTransform1d( f, height, v, z, d );
14971497
for ( int y = 0; y < height; y++ )
14981498
{
1499-
im[ x + y * width ] = d[y];
1499+
im[ x + static_cast< std::size_t>( y ) * width ] = d[y];
15001500
}
15011501
}
15021502

@@ -1508,12 +1508,12 @@ void QgsShapeburstFillSymbolLayer::distanceTransform2d( double *im, int width, i
15081508

15091509
for ( int x = 0; x < width; x++ )
15101510
{
1511-
f[x] = im[ x + y * width ];
1511+
f[x] = im[ x + static_cast< std::size_t>( y ) * width ];
15121512
}
15131513
distanceTransform1d( f, width, v, z, d );
15141514
for ( int x = 0; x < width; x++ )
15151515
{
1516-
im[ x + y * width ] = d[x];
1516+
im[ x + static_cast< std::size_t>( y ) * width ] = d[x];
15171517
}
15181518
}
15191519

@@ -1529,11 +1529,11 @@ double *QgsShapeburstFillSymbolLayer::distanceTransform( QImage *im, QgsRenderCo
15291529
int width = im->width();
15301530
int height = im->height();
15311531

1532-
double *dtArray = new double[width * height];
1532+
double *dtArray = new double[static_cast< std::size_t>( width ) * height];
15331533

15341534
//load qImage to array
15351535
QRgb tmpRgb;
1536-
int idx = 0;
1536+
std::size_t idx = 0;
15371537
for ( int heightIndex = 0; heightIndex < height; ++heightIndex )
15381538
{
15391539
if ( context.renderingStopped() )
@@ -1575,7 +1575,7 @@ void QgsShapeburstFillSymbolLayer::dtArrayToQImage( double *array, QImage *im, Q
15751575
{
15761576
//no max distance specified in symbol properties, so calculate from maximum value in distance transform results
15771577
double dtMaxValue = array[0];
1578-
for ( int i = 1; i < ( width * height ); ++i )
1578+
for ( std::size_t i = 1; i < static_cast< std::size_t >( width ) * height; ++i )
15791579
{
15801580
if ( array[i] > dtMaxValue )
15811581
{
@@ -1593,7 +1593,7 @@ void QgsShapeburstFillSymbolLayer::dtArrayToQImage( double *array, QImage *im, Q
15931593
}
15941594

15951595
//update the pixels in the provided QImage
1596-
int idx = 0;
1596+
std::size_t idx = 0;
15971597
double squaredVal = 0;
15981598
double pixVal = 0;
15991599

0 commit comments

Comments
 (0)
Please sign in to comment.