From 1766f01b7afdddad907cfbcbc9d1a33b99623d85 Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Sat, 23 Jul 2022 16:18:35 +0200 Subject: [PATCH] UI: Fix crash on macOS if no python path is set in configuration Obvious fix guarding against calling the std::string constructor with a NULL pointer. --- .../frontend-tools/scripts.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/UI/frontend-plugins/frontend-tools/scripts.cpp b/UI/frontend-plugins/frontend-tools/scripts.cpp index 4145ac681..074c30d13 100644 --- a/UI/frontend-plugins/frontend-tools/scripts.cpp +++ b/UI/frontend-plugins/frontend-tools/scripts.cpp @@ -653,15 +653,18 @@ extern "C" void InitScripts() config_get_string(config, "Python", "Path" ARCH_NAME); #ifdef __APPLE__ - std::string _python_path(python_path); - std::size_t pos = _python_path.find("/Python.framework/Versions"); + if (python_path && *python_path) { + std::string _python_path(python_path); + std::size_t pos = + _python_path.find("/Python.framework/Versions"); - if (pos != std::string::npos) { - std::string _temp = _python_path.substr(0, pos); - config_set_string(config, "Python", "Path" ARCH_NAME, - _temp.c_str()); - config_save(config); - python_path = _temp.c_str(); + if (pos != std::string::npos) { + std::string _temp = _python_path.substr(0, pos); + config_set_string(config, "Python", "Path" ARCH_NAME, + _temp.c_str()); + config_save(config); + python_path = _temp.c_str(); + } } #endif