Skip to content

Commit

Permalink
Fix false-positive -Wformat-truncation with clang 18 on fedora:rawhid…
Browse files Browse the repository at this point in the history
…e CI
  • Loading branch information
rouault committed Mar 4, 2024
1 parent e04bd07 commit 920b39b
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 920b39b

Please sign in to comment.