Skip to content

Commit

Permalink
Config: remove flawed qstring_data_copy and add toUtf8() macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane L committed Mar 14, 2018
1 parent 357691b commit 389ef2a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 17 deletions.
10 changes: 6 additions & 4 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include "Config.h"
#include "Utils.h"

#define QT_TO_UTF8(str) str.toUtf8().constData()

Config* Config::_instance = new Config();

Config::Config() :
Expand Down Expand Up @@ -62,9 +64,9 @@ Config::Config() :
config_set_default_bool(obsConfig,
SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired);
config_set_default_string(obsConfig,
SECTION_NAME, PARAM_SECRET, qstring_data_copy(Secret));
SECTION_NAME, PARAM_SECRET, QT_TO_UTF8(Secret));
config_set_default_string(obsConfig,
SECTION_NAME, PARAM_SALT, qstring_data_copy(Salt));
SECTION_NAME, PARAM_SALT, QT_TO_UTF8(Salt));
}

mbedtls_entropy_init(&entropy);
Expand Down Expand Up @@ -104,9 +106,9 @@ void Config::Save() {

config_set_bool(obsConfig, SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired);
config_set_string(obsConfig, SECTION_NAME, PARAM_SECRET,
qstring_data_copy(Secret));
QT_TO_UTF8(Secret));
config_set_string(obsConfig, SECTION_NAME, PARAM_SALT,
qstring_data_copy(Salt));
QT_TO_UTF8(Salt));

config_save(obsConfig);
}
Expand Down
7 changes: 0 additions & 7 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>

Q_DECLARE_METATYPE(OBSScene);

const char* qstring_data_copy(QString value) {
QByteArray stringData = value.toUtf8();
const char* constStringData = new const char[stringData.size()]();
memcpy((void*)constStringData, stringData.constData(), stringData.size());
return constStringData;
}

obs_data_array_t* Utils::StringListToArray(char** strings, char* key) {
if (!strings)
return obs_data_array_create();
Expand Down
2 changes: 0 additions & 2 deletions src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include <obs-module.h>
#include <util/config-file.h>

const char* qstring_data_copy(QString value);

class Utils {
public:
static obs_data_array_t* StringListToArray(char** strings, char* key);
Expand Down
1 change: 0 additions & 1 deletion src/forms/settings-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include "../Config.h"
#include "../WSServer.h"
#include "settings-dialog.h"
#include "ui_settings-dialog.h"

#define CHANGE_ME "changeme"

Expand Down
4 changes: 1 addition & 3 deletions src/forms/settings-dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>

#include <QDialog>

namespace Ui {
class SettingsDialog;
}
#include "ui_settings-dialog.h"

class SettingsDialog : public QDialog
{
Expand Down

0 comments on commit 389ef2a

Please sign in to comment.