From 2388f5d33fa2dac91cfaa205ed9bd797ed936fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Mon, 5 Oct 2020 16:44:23 +0200 Subject: [PATCH] Don't crash if WXPREFIX env. variable is set Change wxGetInstallPrefix() to return a string instead of const wxChar*. The latter was incorrectly obtained from a temporary string if WXPREFIX was set. While it's possible to fix in a backward compatible manner without changing the function's signature, it's not worth the effort for something pretty obscure and used mostly internally. --- docs/changes.txt | 2 ++ include/wx/utils.h | 2 +- src/common/utilscmn.cpp | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index a5196548aa..ba14312ee6 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -105,6 +105,8 @@ Changes in behaviour not resulting in compilation errors - wxFileDialog::GetPath() and wxFileDialog::GetFilename() now assert and return an empty string if called on dialogs with the wxFD_MULTIPLE style. +- wxGetInstallPrefix() now returns wxString. + Changes in behaviour which may result in build errors ----------------------------------------------------- diff --git a/include/wx/utils.h b/include/wx/utils.h index c6d35299c2..3f4aea8daf 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -162,7 +162,7 @@ WXDLLIMPEXP_BASE wxLinuxDistributionInfo wxGetLinuxDistributionInfo(); WXDLLIMPEXP_BASE wxString wxNow(); // Return path where wxWidgets is installed (mostly useful in Unices) -WXDLLIMPEXP_BASE const wxChar *wxGetInstallPrefix(); +WXDLLIMPEXP_BASE wxString wxGetInstallPrefix(); // Return path to wxWin data (/usr/share/wx/%{version}) (Unices) WXDLLIMPEXP_BASE wxString wxGetDataDir(); diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 05b6fa002f..bcfee48b33 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -182,12 +182,12 @@ void wxUsleep(unsigned long milliseconds) } #endif -const wxChar *wxGetInstallPrefix() +wxString wxGetInstallPrefix() { wxString prefix; if ( wxGetEnv(wxT("WXPREFIX"), &prefix) ) - return prefix.c_str(); + return prefix; #ifdef wxINSTALL_PREFIX return wxT(wxINSTALL_PREFIX);