aboutsummaryrefslogtreecommitdiff
path: root/src/nix/path-info.cc
diff options
context:
space:
mode:
authorBenjamin Hipple <bhipple@protonmail.com>2018-08-26 18:12:06 -0400
committerEelco Dolstra <edolstra@gmail.com>2018-08-30 16:22:04 +0200
commitc908df881f105d6a1004ae6a0e39da2d0149f3e9 (patch)
treef8ec54310a933b43661a4b644c0f8d052b096bf6 /src/nix/path-info.cc
parent3407a5d9361611ea8b5da9e02a7a1e2f90c928cd (diff)
Avoid overflow and use boost::format
If the user has an object greater than 1024 yottabytes, it'll just display it as N yottabytes instead of overflowing. Swaps to use boost::format strings instead of std::setw and std::setprecision.
Diffstat (limited to 'src/nix/path-info.cc')
-rw-r--r--src/nix/path-info.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc
index ee48d483c..fa4f45fb4 100644
--- a/src/nix/path-info.cc
+++ b/src/nix/path-info.cc
@@ -4,8 +4,9 @@
#include "json.hh"
#include "common-args.hh"
-#include <iomanip>
#include <algorithm>
+#include <boost/format.hpp>
+#include <iomanip>
using namespace nix;
@@ -67,20 +68,20 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
void printSize(int value)
{
if (!humanReadable) {
- std::cout << '\t' << std::setw(11) << value;
+ std::cout << '\t' << boost::format("%11d") % value;
return;
}
- static constexpr std::array<char, 6> idents = {
- ' ', 'K', 'M', 'G', 'T', 'P'
+ static constexpr std::array<char, 9> idents = {
+ ' ', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'
};
size_t power = 0;
double res = value;
- while (res > 1024) {
+ while (res > 1024 && power < idents.size()) {
++power;
res /= 1024;
}
- std::cout << '\t' << std::setw(11) << std::setprecision(3) << res << idents[power];
+ std::cout << '\t' << boost::format("%11.1f") % res << idents[power];
}
void run(ref<Store> store, Paths storePaths) override