hrev43427 adds 2 changesets to branch 'master' old head: f589e913a7c29d771eb03cad57be1877d9581013 new head: f28e19f5be174afa6dd95af9ef35171bd48e3f1f ---------------------------------------------------------------------------- e6f323b: 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. f28e19f: Use the right value as id for the BTranslatorRoster call. The loop counter was used as the id directly instead of using it as the index into the translator_id array. [ Michael Lotz <mmlr@xxxxxxxx> ] ---------------------------------------------------------------------------- 3 files changed, 11 insertions(+), 9 deletions(-) src/apps/screenshot/ScreenshotWindow.cpp | 2 +- src/apps/screenshot/Utility.cpp | 13 +++++++------ src/apps/screenshot/Utility.h | 5 +++-- ############################################################################ Commit: e6f323bb575c150b7f21ff3fbd7a8ecdb04906cc URL: http://cgit.haiku-os.org/haiku/commit/?id=e6f323b Author: Michael Lotz <mmlr@xxxxxxxx> Date: Tue Dec 6 23:16:23 2011 UTC 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. ---------------------------------------------------------------------------- diff --git a/src/apps/screenshot/ScreenshotWindow.cpp b/src/apps/screenshot/ScreenshotWindow.cpp index 9823285..d3ae221 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 6ee873b..7d89b9a 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 eb40b6a..786a9c6 100644 --- a/src/apps/screenshot/Utility.h +++ b/src/apps/screenshot/Utility.h @@ -8,6 +8,7 @@ #include <Point.h> #include <Rect.h> +#include <String.h> 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; }; ############################################################################ Revision: hrev43427 Commit: f28e19f5be174afa6dd95af9ef35171bd48e3f1f URL: http://cgit.haiku-os.org/haiku/commit/?id=f28e19f Author: Michael Lotz <mmlr@xxxxxxxx> Date: Tue Dec 6 23:21:21 2011 UTC Use the right value as id for the BTranslatorRoster call. The loop counter was used as the id directly instead of using it as the index into the translator_id array. ---------------------------------------------------------------------------- diff --git a/src/apps/screenshot/Utility.cpp b/src/apps/screenshot/Utility.cpp index 7d89b9a..992535c 100644 --- a/src/apps/screenshot/Utility.cpp +++ b/src/apps/screenshot/Utility.cpp @@ -222,7 +222,8 @@ Utility::_GetMimeString(uint32 imageType) const const translation_format* formats = NULL; int32 numFormats; - if (roster->GetOutputFormats(x, &formats, &numFormats) == B_OK) { + if (roster->GetOutputFormats(translators[x], &formats, &numFormats) + == B_OK) { for (int32 i = 0; i < numFormats; ++i) { if (formats[i].type == imageType) { delete [] translators;