Merge pull request #63278 from m-kuhn/sprintf

Avoid warnings about unsecure functions
This commit is contained in:
Andrea Giudiceandrea 2025-09-23 16:09:50 +02:00 committed by GitHub
commit b11c30f8fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -563,38 +563,32 @@ bool QgsSpatiaLiteConnection::isRasterlite1Datasource( sqlite3 *handle, const ch
int rows;
int columns;
bool exists = false;
char table_raster[4192];
char sql[4258];
strncpy( table_raster, table, sizeof table_raster );
table_raster[sizeof table_raster - 1] = '\0';
const size_t len = strlen( table_raster );
if ( strlen( table_raster ) < 9 )
QString tableRaster = QString::fromUtf8( table );
if ( !tableRaster.endsWith( QLatin1String( "_metadata" ) ) )
return false;
if ( strcmp( table_raster + len - 9, "_metadata" ) != 0 )
return false;
// OK, possible candidate
strcpy( table_raster + len - 9, "_rasters" );
// checking if the related "_RASTERS table exists
sprintf( sql, "SELECT name FROM sqlite_master WHERE type = 'table' AND name = '%s'", table_raster );
// OK, possible candidate → replace suffix
tableRaster.chop( 9 );
tableRaster += QLatin1String( "_rasters" );
ret = sqlite3_get_table( handle, sql, &results, &rows, &columns, nullptr );
// checking if the related "_RASTERS" table exists
QString sqlStr = QStringLiteral(
"SELECT name FROM sqlite_master WHERE type = 'table' AND name = '%1'"
)
.arg( tableRaster.replace( '\'', QLatin1String( "''" ) ) );
ret = sqlite3_get_table( handle, sqlStr.toUtf8().constData(), &results, &rows, &columns, nullptr );
if ( ret != SQLITE_OK )
return false;
if ( rows < 1 )
;
else
for ( i = 1; i <= rows; i++ )
{
for ( i = 1; i <= rows; i++ )
const char *name = results[( i * columns ) + 0];
if ( name )
{
if ( results[( i * columns ) + 0] )
{
const char *name = results[( i * columns ) + 0];
if ( name )
exists = true;
}
exists = true;
break;
}
}
sqlite3_free_table( results );