diff options
author | Scott Byer <scottbyer@chromium.org> | 2011-04-07 21:16:06 (GMT) |
---|---|---|
committer | Scott Byer <scottbyer@chromium.org> | 2011-04-07 21:16:06 (GMT) |
commit | d5fdbb440ecb16d205cf7edfd33258fc5751a7b4 (patch) | |
tree | 4e26f783e1692508a964278d1c6240c879680c5d /src | |
parent | 9d5fd61c00b34511fd16bce1a3233743c7e4448f (diff) | |
download | Ninja-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.cc | 8 |
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); } } |