summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-02-17 07:35:23 +0100
committerMarc Mutz <marc.mutz@qt.io>2023-02-22 19:24:16 +0100
commit9f5a687ffebbc93ce5f8f25c544aa9129c6366c3 (patch)
treea8140f1daed19a27e8c6a49343a890f126078479 /src/corelib/text
parenta596ea0fe278416b4827ddbb0fffd9c497bd4d88 (diff)
qt_inIsoNametoLCID: protect against a nullptr name
The only user of the function, QCollatorPrivate::init(), passes QLocalePrivate::bcp47Name().constData(). bcp47Name() may return a default-constructed QByteArray (e.g. for QLocale::AnyLanguage), so constData() may be nullptr (QT5_NULL_STRINGS != 1). Passing nullptr to strncmp() or strncpy() is UB, though. Instead of using the nullptr-hardened q... versions of these functions, check name for nullptr once, at the top of the function, and avoid all the lookup code that follows and is known to fail (because windows_to_iso_list does not contain empty entries). This way, we take advantage of the std functions' UB for performance reasons (fewer repeated nullptr checks), instead of being taken advantage of. Qt 5 is not affected, as constData() never returns nullptr there. Pick-to: 6.5 6.4 6.2 Change-Id: I980dace2bca1e983ac526e89fadeb92239ab5f11 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qlocale_win.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp
index 550f7dd464..43324fbfb6 100644
--- a/src/corelib/text/qlocale_win.cpp
+++ b/src/corelib/text/qlocale_win.cpp
@@ -1038,6 +1038,8 @@ static const char *winLangCodeToIsoName(int code)
LCID qt_inIsoNametoLCID(const char *name)
{
+ if (!name)
+ return LOCALE_USER_DEFAULT;
// handle norwegian manually, the list above will fail
if (!strncmp(name, "nb", 2))
return 0x0414;