From a34d7cd1ef5e43dee7f1fa963a7979fd5ee146c4 Mon Sep 17 00:00:00 2001 From: Matti Rauter <matthias@rauter.it> Date: Sun, 21 May 2023 11:13:02 +0200 Subject: [PATCH] COMP: Supress gcc7+ warning in shapefile writer --- src/avalanche/gistools/shapefile.C | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/avalanche/gistools/shapefile.C b/src/avalanche/gistools/shapefile.C index 8de4200..91dad6f 100644 --- a/src/avalanche/gistools/shapefile.C +++ b/src/avalanche/gistools/shapefile.C @@ -1331,7 +1331,20 @@ int shapefile::write(std::string filename) } else if(this->fd_[j] > 0) { - snprintf(formatstr+1, 6, "%d.%df", this->fl_[j], this->fd_[j]); + // TDB: use string concatenation? + // eg, + // std::string fmtstr + // ( + // "%" + std::to_string(this->fl_[j]) + // + "." + std::to_string(this->fd_[j]) + "f" + // ); + + if (snprintf(formatstr+1, 6, "%d.%df", this->fl_[j], this->fd_[j]) < 0) + { + //should never happen but prevents gcc warning + DebugInfo << "Format string exceeds 6 characters - not writing further." << std::endl; + return 0; + } snprintf(buf, buflen+1, formatstr, v_[i][j]); } else -- GitLab