From 8c608ee8b9d5d4913eb3a851cfd9c6f0a87e105d Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 18 Jun 2012 17:07:27 +0100 Subject: [PATCH] Use C++ allocation/freeing for text masking and multiline processing --- src/interface/Textblock.cpp | 7 ++++--- src/interface/Textbox.cpp | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/interface/Textblock.cpp b/src/interface/Textblock.cpp index c37892599..f003a6aee 100644 --- a/src/interface/Textblock.cpp +++ b/src/interface/Textblock.cpp @@ -28,8 +28,8 @@ void Textblock::SetText(std::string text) void Textblock::updateMultiline() { - char * rawText = (char*)malloc(text.length()+1); - memcpy(rawText, text.c_str(), text.length()); + char * rawText = new char[text.length()+1]; + std::copy(text.begin(), text.end(), rawText); rawText[text.length()] = 0; int lines = 1; @@ -60,7 +60,8 @@ void Textblock::updateMultiline() { Size.Y = lines*12; } - textLines = rawText; + textLines = std::string(rawText); + delete[] rawText; } void Textblock::Draw(const Point &screenPos) diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 4c0e267bf..4ea5bd013 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -129,10 +129,10 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool { if(masked) { - char * tempText = new char[text.length()]; + char * tempText = new char[text.length()+1]; std::fill(tempText, tempText+text.length(), 0x8d); tempText[text.length()] = 0; - displayText = tempText; + displayText = std::string(tempText); delete tempText; } else