From: Remi Gacogne Date: Thu, 26 Jan 2023 10:22:13 +0000 (+0100) Subject: rec: Fix 'format string is not a string literal' warning X-Git-Tag: dnsdist-1.8.0-rc1~78^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8b92989b6c55ff5a625041bb082cf57cd6e0eac;p=thirdparty%2Fpdns.git rec: Fix 'format string is not a string literal' warning It turns out that we always use the same format string anyway. --- diff --git a/pdns/recursordist/syncres.cc b/pdns/recursordist/syncres.cc index 4abe7496da..f6c24534f2 100644 --- a/pdns/recursordist/syncres.cc +++ b/pdns/recursordist/syncres.cc @@ -482,10 +482,10 @@ bool SyncRes::s_addExtendedResolutionDNSErrors; // into locale handling code according to tsan. // This allocates a string, but that's nothing compared to what // boost::format is doing and may even be optimized away anyway. -static inline std::string fmtfloat(const char* fmt, double f) +static inline std::string fmtfloat(double f) { char buf[20]; - int ret = snprintf(buf, sizeof(buf), fmt, f); + int ret = snprintf(buf, sizeof(buf), "%0.2f", f); if (ret < 0 || ret >= static_cast(sizeof(buf))) { return "?"; } @@ -2191,7 +2191,7 @@ vector SyncRes::getAddrs(const DNSName& qname, unsigned int depth, else { LOG(", "); } - LOG((addr.toString()) << "(" << fmtfloat("%0.2f", speeds[addr] / 1000.0) << "ms)"); + LOG((addr.toString()) << "(" << fmtfloat(speeds[addr] / 1000.0) << "ms)"); } LOG(endl); } @@ -3036,7 +3036,7 @@ inline std::vector> SyncRes::shuffleInSpeedOrder(NsSet << prefix << " "); } } - LOG(i->first.toLogString() << "(" << fmtfloat("%0.2f", i->second / 1000.0) << "ms)"); + LOG(i->first.toLogString() << "(" << fmtfloat(i->second / 1000.0) << "ms)"); } LOG(endl); } @@ -3067,7 +3067,7 @@ inline vector SyncRes::shuffleForwardSpeed(const vectortoStringWithPort() << "(" << fmtfloat("%0.2f", speeds[*i] / 1000.0) << "ms)"); + LOG((wasRd ? string("+") : string("-")) << i->toStringWithPort() << "(" << fmtfloat(speeds[*i] / 1000.0) << "ms)"); } LOG(endl); }