From 4f5d588bed6c000ba7acfd5c94a4e706ddd14f0d Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Mon, 15 Aug 2016 17:00:06 +0800 Subject: [PATCH] mon/OSDMonitor: get rid of snprintf when formatting output string We can use the standard precision() and fixed method to achieve the same effect. Signed-off-by: xie xingguo --- src/mon/OSDMonitor.cc | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 30fa6c40b11..851da016766 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -585,10 +585,9 @@ int OSDMonitor::reweight_by_utilization(int oload, oss << "oload " << oload << "\n"; oss << "max_change " << max_changef << "\n"; oss << "max_change_osds " << max_osds << "\n"; - char buf[128]; - snprintf(buf, sizeof(buf), "average %04f\noverload %04f\n", - average_util, overload_util); - oss << buf; + oss.precision(4); + oss << std::fixed << average_util << "\n"; + oss << overload_util << "\n"; } bool changed = false; int num_changed = 0; @@ -664,11 +663,9 @@ int OSDMonitor::reweight_by_utilization(int oload, f->dump_float("new_weight", (float)new_weight / (float)0x10000); f->close_section(); } else { - char buf[128]; - snprintf(buf, sizeof(buf), "osd.%d weight %04f -> %04f\n", p->first, - (float)weight / (float)0x10000, - (float)new_weight / (float)0x10000); - oss << buf; + oss << "osd." << p->first << " weight " + << (float)weight / (float)0x10000 << " -> " + << (float)new_weight / (float)0x10000; } if (++num_changed >= max_osds) break; @@ -685,11 +682,9 @@ int OSDMonitor::reweight_by_utilization(int oload, pending_inc.new_weight[p->first] = new_weight; changed = true; } - char buf[128]; - snprintf(buf, sizeof(buf), "osd.%d weight %04f -> %04f\n", p->first, - (float)weight / (float)0x10000, - (float)new_weight / (float)0x10000); - oss << buf; + oss << "osd." << p->first << " weight " + << (float)weight / (float)0x10000 << " -> " + << (float)new_weight / (float)0x10000; if (++num_changed >= max_osds) break; } -- 2.47.3