13
0

fix novice-level mistake that causes localedir to point to random, reusable (typically stack) memory

This commit is contained in:
Paul Davis 2015-04-17 11:00:33 -04:00
parent dff83c77cf
commit 76b28e7ff2
6 changed files with 18 additions and 15 deletions

View File

@ -20,11 +20,13 @@
#ifndef __gtk2_ardour_bundle_env_h__ #ifndef __gtk2_ardour_bundle_env_h__
#define __gtk2_ardour_bundle_env_h__ #define __gtk2_ardour_bundle_env_h__
#include <string>
/** This function must do whatever is necessary to create the right runtime /** This function must do whatever is necessary to create the right runtime
* environment for the GTK2 version of ardour, on a per-platform basis. * environment for the GTK2 version of ardour, on a per-platform basis.
*/ */
void fixup_bundle_environment (int, char* [], const char** localedir); void fixup_bundle_environment (int, char* [], std::string & localedir);
/** Load any fonts required by the GTK2 version of ardour, on a per-platform /** Load any fonts required by the GTK2 version of ardour, on a per-platform
* basis. * basis.

View File

@ -52,7 +52,7 @@ using namespace std;
extern void set_language_preference (); // cocoacarbon.mm extern void set_language_preference (); // cocoacarbon.mm
void void
fixup_bundle_environment (int, char* [], const char** localedir) fixup_bundle_environment (int, char* [], string & localedir)
{ {
if (!g_getenv ("ARDOUR_BUNDLED")) { if (!g_getenv ("ARDOUR_BUNDLED")) {
return; return;
@ -84,7 +84,7 @@ fixup_bundle_environment (int, char* [], const char** localedir)
lpath.push_back (bundle_dir); lpath.push_back (bundle_dir);
lpath.push_back ("Resources"); lpath.push_back ("Resources");
lpath.push_back ("locale"); lpath.push_back ("locale");
(*localedir) = strdup (Glib::build_filename (lpath).c_str()); localedir = strdup (Glib::build_filename (lpath).c_str());
} }
#endif #endif

View File

@ -46,7 +46,7 @@ using namespace ARDOUR;
using namespace std; using namespace std;
void void
fixup_bundle_environment (int /*argc*/, char* argv[], const char** localedir) fixup_bundle_environment (int /*argc*/, char* argv[], string & localedir)
{ {
/* THIS IS FOR LINUX - its just about the only place where its /* THIS IS FOR LINUX - its just about the only place where its
* acceptable to build paths directly using '/'. * acceptable to build paths directly using '/'.
@ -63,14 +63,14 @@ fixup_bundle_environment (int /*argc*/, char* argv[], const char** localedir)
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
if (!ARDOUR::translations_are_enabled ()) { if (!ARDOUR::translations_are_enabled ()) {
(*localedir) = "/this/cannot/exist"; localedir = "/this/cannot/exist";
} else { } else {
/* force localedir into the bundle */ /* force localedir into the bundle */
vector<string> lpath; vector<string> lpath;
lpath.push_back (dir_path); lpath.push_back (dir_path);
lpath.push_back ("share"); lpath.push_back ("share");
lpath.push_back ("locale"); lpath.push_back ("locale");
(*localedir) = canonical_path (Glib::build_filename (lpath)).c_str(); localedir = canonical_path (Glib::build_filename (lpath)).c_str();
} }
#endif #endif

View File

@ -18,6 +18,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#inc;ude <string>
#include "bundle_env.h" #include "bundle_env.h"
#include "i18n.h" #include "i18n.h"
@ -84,7 +85,7 @@ get_install_path ()
void void
fixup_bundle_environment (int, char* [], const char** localedir) fixup_bundle_environment (int, char* [], string & localedir)
{ {
EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true)); EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true));
/* what to do ? */ /* what to do ? */
@ -103,7 +104,7 @@ fixup_bundle_environment (int, char* [], const char** localedir)
Glib::setenv ("GTK_LOCALEDIR", path, true); Glib::setenv ("GTK_LOCALEDIR", path, true);
// and return the same path to our caller // and return the same path to our caller
(*localedir) = strdup (path.c_str()); localedir = path;
} }
const char *cstr; const char *cstr;

View File

@ -341,7 +341,7 @@ string clearlooks_la_file;
} }
void void
fixup_bundle_environment (int argc, char* argv[], const char** localedir) fixup_bundle_environment (int argc, char* argv[], string & localedir)
{ {
std::string exec_path = argv[0]; std::string exec_path = argv[0];
std::string dir_path = Glib::path_get_dirname (exec_path); std::string dir_path = Glib::path_get_dirname (exec_path);
@ -450,7 +450,7 @@ fixup_bundle_environment (int argc, char* argv[], const char** localedir)
Glib::setenv ("GTK_LOCALEDIR", path, true); Glib::setenv ("GTK_LOCALEDIR", path, true);
// and return the same path to our caller // and return the same path to our caller
(*localedir) = strdup (path.c_str()); localedir = path;
} }

View File

@ -74,7 +74,7 @@ TextReceiver text_receiver ("ardour");
extern int curvetest (string); extern int curvetest (string);
static ARDOUR_UI *ui = 0; static ARDOUR_UI *ui = 0;
static const char* localedir = LOCALEDIR; static string localedir (LOCALEDIR);
void void
gui_jack_error () gui_jack_error ()
@ -253,7 +253,7 @@ int main (int argc, char *argv[])
{ {
ARDOUR::check_for_old_configuration_files(); ARDOUR::check_for_old_configuration_files();
fixup_bundle_environment (argc, argv, &localedir); fixup_bundle_environment (argc, argv, localedir);
load_custom_fonts(); /* needs to happen before any gtk and pango init calls */ load_custom_fonts(); /* needs to happen before any gtk and pango init calls */
@ -277,7 +277,7 @@ int main (int argc, char *argv[])
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
cerr << "bind txt domain [" << PACKAGE << "] to " << localedir << endl; cerr << "bind txt domain [" << PACKAGE << "] to " << localedir << endl;
(void) bindtextdomain (PACKAGE, localedir); (void) bindtextdomain (PACKAGE, localedir.c_str());
/* our i18n translations are all in UTF-8, so make sure /* our i18n translations are all in UTF-8, so make sure
that even if the user locale doesn't specify UTF-8, that even if the user locale doesn't specify UTF-8,
we use that when handling them. we use that when handling them.
@ -330,7 +330,7 @@ int main (int argc, char *argv[])
<< endl; << endl;
} }
if (!ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization, localedir)) { if (!ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization, localedir.c_str())) {
error << string_compose (_("could not initialize %1."), PROGRAM_NAME) << endmsg; error << string_compose (_("could not initialize %1."), PROGRAM_NAME) << endmsg;
exit (1); exit (1);
} }
@ -346,7 +346,7 @@ int main (int argc, char *argv[])
#endif #endif
try { try {
ui = new ARDOUR_UI (&argc, &argv, localedir); ui = new ARDOUR_UI (&argc, &argv, localedir.c_str());
} catch (failed_constructor& err) { } catch (failed_constructor& err) {
error << string_compose (_("could not create %1 GUI"), PROGRAM_NAME) << endmsg; error << string_compose (_("could not create %1 GUI"), PROGRAM_NAME) << endmsg;
exit (1); exit (1);