summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorScott Byer <scottbyer@chromium.org>2011-04-07 21:16:06 (GMT)
committerScott Byer <scottbyer@chromium.org>2011-04-07 21:16:06 (GMT)
commitd5fdbb440ecb16d205cf7edfd33258fc5751a7b4 (patch)
tree4e26f783e1692508a964278d1c6240c879680c5d /src
parent9d5fd61c00b34511fd16bce1a3233743c7e4448f (diff)
downloadNinja-d5fdbb440ecb16d205cf7edfd33258fc5751a7b4.zip
Ninja-d5fdbb440ecb16d205cf7edfd33258fc5751a7b4.tar.gz
Ninja-d5fdbb440ecb16d205cf7edfd33258fc5751a7b4.tar.bz2
Fix an exception when terminal is narrow or set for unlimited width
Diffstat (limited to 'src')
-rw-r--r--src/build.cc8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/build.cc b/src/build.cc
index 09c362a..ba7f1be 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -106,12 +106,14 @@ void BuildStatus::PrintStatus(Edge* edge) {
to_print = edge->EvaluateCommand();
if (smart_terminal_) {
- // Limit output to width of the terminal so we don't cause line-wrapping.
+ // Limit output to width of the terminal if provided so we don't cause
+ // line-wrapping.
winsize size;
- if (ioctl(0, TIOCGWINSZ, &size) == 0) {
+ if ((ioctl(0, TIOCGWINSZ, &size) == 0) && size.ws_col) {
const int kMargin = 15; // Space for [xxx/yyy] and "...".
if (to_print.size() + kMargin > size.ws_col) {
- int substr = to_print.size() + kMargin - size.ws_col;
+ int substr = std::min(to_print.size(),
+ to_print.size() + kMargin - size.ws_col);
to_print = "..." + to_print.substr(substr);
}
}