From e6f323bb575c150b7f21ff3fbd7a8ecdb04906cc Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Wed, 7 Dec 2011 00:16:23 +0100 Subject: [PATCH] Strings owned by local stack objects can't be returned. The BString is destroyed when the function returns and takes the storage pointed to by BString::String() with it, so returning such a pointer is bogus. Instead the return type is now a BString which takes over ownership of the string. --- src/apps/screenshot/ScreenshotWindow.cpp | 2 +- src/apps/screenshot/Utility.cpp | 10 +++++----- src/apps/screenshot/Utility.h | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/apps/screenshot/ScreenshotWindow.cpp b/src/apps/screenshot/ScreenshotWindow.cpp index 9823285351..d3ae2212c0 100644 --- a/src/apps/screenshot/ScreenshotWindow.cpp +++ b/src/apps/screenshot/ScreenshotWindow.cpp @@ -713,7 +713,7 @@ ScreenshotWindow::_FindValidFileName(const char* name) if (orgPath == NULL) return baseName; - fExtension = BString(fUtility.GetFileNameExtension(fImageFileType)); + fExtension = fUtility.GetFileNameExtension(fImageFileType); BPath outputPath = orgPath; BString fileName; diff --git a/src/apps/screenshot/Utility.cpp b/src/apps/screenshot/Utility.cpp index 6ee873b5bc..7d89b9a8cc 100644 --- a/src/apps/screenshot/Utility.cpp +++ b/src/apps/screenshot/Utility.cpp @@ -120,7 +120,7 @@ Utility::Save(BBitmap** screenshot, const char* fileName, uint32 imageType) if (nodeInfo.InitCheck() != B_OK) return B_ERROR; - nodeInfo.SetType(_GetMimeString(imageType)); + nodeInfo.SetType(_GetMimeString(imageType).String()); return B_OK; } @@ -187,10 +187,10 @@ Utility::MakeScreenshot(bool includeMouse, bool activeWindow, } -const char* +BString Utility::GetFileNameExtension(uint32 imageType) const { - BMimeType mimeType(_GetMimeString(imageType)); + BMimeType mimeType(_GetMimeString(imageType).String()); BString extension(""); BMessage message; @@ -203,11 +203,11 @@ Utility::GetFileNameExtension(uint32 imageType) const extension.SetTo(""); } - return extension.String(); + return extension; } -const char* +BString Utility::_GetMimeString(uint32 imageType) const { const char *dummy = ""; diff --git a/src/apps/screenshot/Utility.h b/src/apps/screenshot/Utility.h index eb40b6a8cd..786a9c6bd1 100644 --- a/src/apps/screenshot/Utility.h +++ b/src/apps/screenshot/Utility.h @@ -8,6 +8,7 @@ #include #include +#include class BBitmap; @@ -27,7 +28,7 @@ public: uint32 imageType) const; BBitmap* MakeScreenshot(bool includeCursor, bool activeWindow, bool includeBorder) const; - const char* GetFileNameExtension(uint32 imageType) const; + BString GetFileNameExtension(uint32 imageType) const; BBitmap* wholeScreen; BBitmap* cursorBitmap; @@ -42,7 +43,7 @@ public: private: void _MakeTabSpaceTransparent(BBitmap* screenshot, BRect frame) const; - const char* _GetMimeString(uint32 imageType) const; + BString _GetMimeString(uint32 imageType) const; };