diff options
author | Maximilian Güntner <maximilian.guentner@gmail.com> | 2013-11-01 18:23:06 +0100 |
---|---|---|
committer | Maximilian Güntner <maximilian.guentner@gmail.com> | 2013-11-02 02:55:02 +0100 |
commit | 2ef80930ff4ac15c7d68e7b3b8935c2121029fd3 (patch) | |
tree | 6122a41a4dc0053e7e0948d9270c69cee52df13d | |
parent | 9e635392373cdc56fb3a897ea491e7c33fdbd424 (diff) | |
download | subsurface-2ef80930ff4ac15c7d68e7b3b8935c2121029fd3.tar.gz |
change the key from const char * to QByteArray
if trGettext() gets called with a *text that resides
in the stack, the QHash will return incorrect values after
the second call of trGettext() with that *text.
Example (assuming nothing has been translated):
void func(const char *text) {
char *translated = trGettext(text);
doSomethingWith(translated);
}
func("foo"); (1)
func("bar"); (2)
(1) *translated is "foo"
(2) *translated should be "bar" but is "foo" because
the key (const char*) points to the value "foo"
which has been set in the previous call (1).
Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
-rw-r--r-- | gettextfromc.cpp | 2 | ||||
-rw-r--r-- | gettextfromc.h | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/gettextfromc.cpp b/gettextfromc.cpp index 1730b52b0..c3b822ff5 100644 --- a/gettextfromc.cpp +++ b/gettextfromc.cpp @@ -4,7 +4,7 @@ const char *gettextFromC::trGettext(const char *text) { - QByteArray &result = translationCache[text]; + QByteArray &result = translationCache[QByteArray(text)]; if (result.isEmpty()) result = tr(text).toUtf8(); return result.constData(); diff --git a/gettextfromc.h b/gettextfromc.h index 19f02fc96..6b5f7b184 100644 --- a/gettextfromc.h +++ b/gettextfromc.h @@ -12,7 +12,7 @@ public: static gettextFromC *instance(); const char *trGettext(const char *text); void reset(void); - QHash <const char *, QByteArray> translationCache; + QHash <QByteArray , QByteArray> translationCache; }; #endif // GETTEXTFROMC_H |