summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2014-12-02 06:15:50 (GMT)
committerNico Weber <nicolasweber@gmx.de>2014-12-02 06:15:50 (GMT)
commit2786f6f8de711251646daca957dbd02d2a95833e (patch)
tree8b996ea33932ad621ddaade4e2128e7dd5c950fd
parent9f73abaaca70e2247e6662e4493a6f1aa24fc233 (diff)
parente28b1aaf5d379211d290cabb5d78c8bf24c6085b (diff)
downloadNinja-2786f6f8de711251646daca957dbd02d2a95833e.zip
Ninja-2786f6f8de711251646daca957dbd02d2a95833e.tar.gz
Ninja-2786f6f8de711251646daca957dbd02d2a95833e.tar.bz2
Merge pull request #872 from nico/vec
win/lineprinter: Use a vector instead of manual memory management.
-rw-r--r--src/line_printer.cc12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/line_printer.cc b/src/line_printer.cc
index 8e7b8f1..e11bcc3 100644
--- a/src/line_printer.cc
+++ b/src/line_printer.cc
@@ -75,16 +75,12 @@ void LinePrinter::Print(string to_print, LineType type) {
static_cast<SHORT>(csbi.dwCursorPosition.X + csbi.dwSize.X - 1),
csbi.dwCursorPosition.Y
};
- CHAR_INFO* char_data = new CHAR_INFO[csbi.dwSize.X];
- memset(char_data, 0, sizeof(CHAR_INFO) * csbi.dwSize.X);
- for (int i = 0; i < csbi.dwSize.X; ++i) {
- char_data[i].Char.AsciiChar = ' ';
+ vector<CHAR_INFO> char_data(csbi.dwSize.X);
+ for (size_t i = 0; i < static_cast<size_t>(csbi.dwSize.X); ++i) {
+ char_data[i].Char.AsciiChar = i < to_print.size() ? to_print[i] : ' ';
char_data[i].Attributes = csbi.wAttributes;
}
- for (size_t i = 0; i < to_print.size(); ++i)
- char_data[i].Char.AsciiChar = to_print[i];
- WriteConsoleOutput(console_, char_data, buf_size, zero_zero, &target);
- delete[] char_data;
+ WriteConsoleOutput(console_, &char_data[0], buf_size, zero_zero, &target);
#else
// Limit output to width of the terminal if provided so we don't cause
// line-wrapping.