summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-04-28 12:33:28 -0700
committerGuy Harris <guy@alum.mit.edu>2016-04-28 19:34:02 +0000
commit232b2de7bb008a2bc7c3e5eece04aab16215d24c (patch)
tree488390f23d6b9c2d18068889b716425466879c88
parent7150588d23d5ab844dd99507ec94831375a07b67 (diff)
downloadwireshark-232b2de7bb008a2bc7c3e5eece04aab16215d24c.tar.gz
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>
-rw-r--r--ui/language.c17
-rw-r--r--ui/language.h2
-rw-r--r--ui/qt/main_window_preferences_frame.cpp2
-rw-r--r--ui/qt/wireshark_application.cpp3
4 files changed, 19 insertions, 5 deletions
diff --git a/ui/language.c b/ui/language.c
index 65a338011e..2bc721aafa 100644
--- a/ui/language.c
+++ b/ui/language.c
@@ -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);
diff --git a/ui/language.h b/ui/language.h
index 8b94d23f69..988461befc 100644
--- a/ui/language.h
+++ b/ui/language.h
@@ -28,6 +28,8 @@
extern "C" {
#endif /* __cplusplus */
+#define USE_SYSTEM_LANGUAGE "system"
+
extern char *language;
extern void read_language_prefs(void);
diff --git a/ui/qt/main_window_preferences_frame.cpp b/ui/qt/main_window_preferences_frame.cpp
index b876ff3d4f..b3927c594e 100644
--- a/ui/qt/main_window_preferences_frame.cpp
+++ b/ui/qt/main_window_preferences_frame.cpp
@@ -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) {
diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp
index eeade6438c..523907555e 100644
--- a/ui/qt/wireshark_application.cpp
+++ b/ui/qt/wireshark_application.cpp
@@ -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;