Skip to content

Commit

Permalink
Merge pull request #9376 from rouault/fix_clang18_warning
Browse files Browse the repository at this point in the history
Fix false-positive -Wformat-truncation with clang 18 on fedora:rawhide CI
  • Loading branch information
rouault authored Mar 4, 2024
2 parents e04bd07 + 920b39b commit fe3cf27
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions frmts/nitf/nitfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4705,19 +4705,17 @@ GDALDataset *NITFDataset::NITFCreateCopy(const char *pszFilename,
/* Write GEOLOB TRE */
/* --------------------------------------------------------------------
*/
char szGEOLOB[48 + 1];
// Extra (useless) bytes to avoid CLang 18 erroneous -Wformat-truncation
constexpr int MARGIN_FOR_CLANG_18 = 2;
char szGEOLOB[48 + 1 + MARGIN_FOR_CLANG_18];
const double dfARV = 360.0 / adfGeoTransform[1];
const double dfBRV = 360.0 / -adfGeoTransform[5];
const double dfLSO = adfGeoTransform[0];
const double dfPSO = adfGeoTransform[3];
snprintf(szGEOLOB, sizeof(szGEOLOB), "%09d",
static_cast<int>(dfARV + 0.5));
snprintf(szGEOLOB + 9, sizeof(szGEOLOB) - (9), "%09d",
static_cast<int>(dfBRV + 0.5));
snprintf(szGEOLOB + 9 + 9, sizeof(szGEOLOB) - (9 + 9),
"%#+015.10f", dfLSO);
snprintf(szGEOLOB + 9 + 9 + 15, sizeof(szGEOLOB) - (9 + 9 + 15),
"%#+015.10f", dfPSO);
CPLsnprintf(szGEOLOB, sizeof(szGEOLOB),
"%09d%09d%#+015.10f%#+015.10f",
static_cast<int>(dfARV + 0.5),
static_cast<int>(dfBRV + 0.5), dfLSO, dfPSO);

CPLString osGEOLOB("TRE=GEOLOB=");
osGEOLOB += szGEOLOB;
Expand Down

0 comments on commit fe3cf27

Please sign in to comment.