Use "system" for "use system language", and don't try to print a null string.
Add a #define USE_SYSTEM_LANGUAGE for the language string meaning "use the system setting", and use that instead of hardcoding "system" in various places. If "language" is null, don't try to write it to the file with fprintf() - on *most* systems, that prints "(null)", but on some systems, such as Solaris, it *crashes*. Write USE_SYSTEM_LANGUAGE instead. Check for "(null)" and treat it as meaning "use the system language". Map "auto" to "use the system language" as well, for backwards compatibility. Change-Id: Iba9be540a5139e9cca8bddd0761ee4cbf0f79a49 Reviewed-on: https://code.wireshark.org/review/15147 Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
parent
7150588d23
commit
232b2de7bb
@ -48,8 +48,19 @@ read_language_pref(gchar *key, const gchar *value,
|
||||
if (strcmp(key, LANGUAGE_PREF_LANGUAGE) == 0) {
|
||||
if (language)
|
||||
g_free(language);
|
||||
if (!value || !*value)
|
||||
language = g_strdup("auto");
|
||||
/*
|
||||
* For backwards compatibility, treat "auto" as meaning "use the
|
||||
* system language".
|
||||
*
|
||||
* To handle the old buggy code that didn't check whether "language"
|
||||
* was null before trying to print it, treat "(null)" - which many,
|
||||
* but *NOT* all, system printfs print for a null pointer (some
|
||||
* printfs, such as the one in Solaris, *crash* with %s and a null
|
||||
* pointer) - as meaning "use the system language".
|
||||
*/
|
||||
if (!value || !*value || strcmp(value, "auto") == 0 ||
|
||||
strcmp(value, "(null)") == 0)
|
||||
language = g_strdup(USE_SYSTEM_LANGUAGE);
|
||||
else
|
||||
language = g_strdup(value);
|
||||
}
|
||||
@ -113,7 +124,7 @@ write_language_prefs(void)
|
||||
"# So be careful, if you want to make manual changes here.\n"
|
||||
"\n", rf);
|
||||
|
||||
fprintf(rf, LANGUAGE_PREF_LANGUAGE ": %s\n", language);
|
||||
fprintf(rf, LANGUAGE_PREF_LANGUAGE ": %s\n", language ? language : USE_SYSTEM_LANGUAGE);
|
||||
|
||||
fclose(rf);
|
||||
|
||||
|
@ -28,6 +28,8 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define USE_SYSTEM_LANGUAGE "system"
|
||||
|
||||
extern char *language;
|
||||
|
||||
extern void read_language_prefs(void);
|
||||
|
@ -96,7 +96,7 @@ MainWindowPreferencesFrame::MainWindowPreferencesFrame(QWidget *parent) :
|
||||
ui->languageComboBox->addItem(ico, lang, locale);
|
||||
}
|
||||
|
||||
ui->languageComboBox->setItemData(0, "system");
|
||||
ui->languageComboBox->setItemData(0, USE_SYSTEM_LANGUAGE);
|
||||
ui->languageComboBox->model()->sort(0);
|
||||
|
||||
for (int i = 0; i < ui->languageComboBox->count(); i += 1) {
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "ui/decode_as_utils.h"
|
||||
#include "ui/preference_utils.h"
|
||||
#include "ui/iface_lists.h"
|
||||
#include "ui/language.h"
|
||||
#include "ui/recent.h"
|
||||
#include "ui/simple_dialog.h"
|
||||
#include "ui/util.h"
|
||||
@ -1055,7 +1056,7 @@ void WiresharkApplication::loadLanguage(const QString& newLanguage)
|
||||
QLocale locale;
|
||||
QString localeLanguage;
|
||||
|
||||
if (newLanguage.isEmpty() || newLanguage == "system") {
|
||||
if (newLanguage.isEmpty() || newLanguage == USE_SYSTEM_LANGUAGE) {
|
||||
localeLanguage = QLocale::system().name();
|
||||
} else {
|
||||
localeLanguage = newLanguage;
|
||||
|
Loading…
x
Reference in New Issue
Block a user