]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Fix 'format string is not a string literal' warning
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 26 Jan 2023 10:22:13 +0000 (11:22 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 26 Jan 2023 10:22:13 +0000 (11:22 +0100)
It turns out that we always use the same format string anyway.

pdns/recursordist/syncres.cc

index 4abe7496da2a38a2c18f697d62c6c4aa72b8e082..f6c24534f29f4932d3164387b27b3883c46f6164 100644 (file)
@@ -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<int>(sizeof(buf))) {
     return "?";
   }
@@ -2191,7 +2191,7 @@ vector<ComboAddress> 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<std::pair<DNSName, float>> 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<ComboAddress> SyncRes::shuffleForwardSpeed(const vector<ComboAddre
               << prefix << "             ");
         }
       }
-      LOG((wasRd ? string("+") : string("-")) << i->toStringWithPort() << "(" << fmtfloat("%0.2f", speeds[*i] / 1000.0) << "ms)");
+      LOG((wasRd ? string("+") : string("-")) << i->toStringWithPort() << "(" << fmtfloat(speeds[*i] / 1000.0) << "ms)");
     }
     LOG(endl);
   }