summaryrefslogtreecommitdiffstats
path: root/src/util.cc
diff options
context:
space:
mode:
authorKevin Robert Stravers <macocio@gmail.com>2019-09-24 11:24:02 (GMT)
committerKevin Robert Stravers <macocio@gmail.com>2019-09-28 22:15:09 (GMT)
commit04ce2ea7a2930b32655823d55a8ff9865a37d6c2 (patch)
tree8ba0ad23e09c9bc9bf22e0c1641c819cd13d25e1 /src/util.cc
parent21bd971ea9381e6c36d3a3be17a501899922ff73 (diff)
downloadNinja-04ce2ea7a2930b32655823d55a8ff9865a37d6c2.zip
Ninja-04ce2ea7a2930b32655823d55a8ff9865a37d6c2.tar.gz
Ninja-04ce2ea7a2930b32655823d55a8ff9865a37d6c2.tar.bz2
Ensure substring indexing never goes negative
With widths lower than 4, the ElideMiddle function would crash because its substring access would wrap around and attempt to access the max size_t value. This patch fixes that.
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index 666cf9d..70096cd 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -596,6 +596,12 @@ double GetLoadAverage() {
#endif // _WIN32
string ElideMiddle(const string& str, size_t width) {
+ switch (width) {
+ case 0: return "";
+ case 1: return ".";
+ case 2: return "..";
+ case 3: return "...";
+ }
const int kMargin = 3; // Space for "...".
string result = str;
if (result.size() > width) {