From 4a12e2cb25ee64333acab9ae60a4052105a02242 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Sat, 4 May 2013 19:15:44 +1000 Subject: Replacing raw pointers and allocations with std::string and std::vector. Don't check result of new as failures throw an exception. --- cocoa/ScintillaView.mm | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'cocoa/ScintillaView.mm') diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index 7f6b4991e..30cc614f4 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -1223,22 +1223,18 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa { NSString *result = @""; - char *buffer(0); const long length = mBackend->WndProc(SCI_GETSELTEXT, 0, 0); if (length > 0) { - buffer = new char[length + 1]; + std::string buffer(length + 1, '\0'); try { - mBackend->WndProc(SCI_GETSELTEXT, length + 1, (sptr_t) buffer); + mBackend->WndProc(SCI_GETSELTEXT, length + 1, (sptr_t) &buffer[0]); - result = [NSString stringWithUTF8String: buffer]; - delete[] buffer; + result = [NSString stringWithUTF8String: buffer.c_str()]; } catch (...) { - delete[] buffer; - buffer = 0; } } @@ -1255,22 +1251,18 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa { NSString *result = @""; - char *buffer(0); const long length = mBackend->WndProc(SCI_GETLENGTH, 0, 0); if (length > 0) { - buffer = new char[length + 1]; + std::string buffer(length + 1, '\0'); try { - mBackend->WndProc(SCI_GETTEXT, length + 1, (sptr_t) buffer); + mBackend->WndProc(SCI_GETTEXT, length + 1, (sptr_t) &buffer[0]); - result = [NSString stringWithUTF8String: buffer]; - delete[] buffer; + result = [NSString stringWithUTF8String: buffer.c_str()]; } catch (...) { - delete[] buffer; - buffer = 0; } } -- cgit v1.2.3