diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-05-29 21:54:22 +0300 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-06-05 23:35:21 +0300 |
commit | ef53352dbc0a149f6bc6eab555887ac646914144 (patch) | |
tree | 25ef60ae04140cd0654f7ce0b7332ba47309611d /src/widgets/dialogs/qfiledialog.cpp | |
parent | 79710abf950e47971836a787f24e7c14aeccc183 (diff) |
QFileDialog: use ::sysconf() to get initial passwd struct buffer size
Use QVLA since buf is no techincally a var-length-array.
Change-Id: I334cf2d1f9ef162495ed223a8e48e1b8e674afc0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/dialogs/qfiledialog.cpp')
-rw-r--r-- | src/widgets/dialogs/qfiledialog.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 7461a643ad..6b146bbaa5 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -1109,13 +1109,15 @@ static QString homeDirFromPasswdEntry(const QString &path, const QByteArray &use #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_WASM) passwd pw; passwd *tmpPw; - char buf[200]; - const int bufSize = sizeof(buf); + long bufSize = ::sysconf(_SC_GETPW_R_SIZE_MAX); + if (bufSize == -1) + bufSize = 1024; + QVarLengthArray<char, 1024> buf(bufSize); int err = 0; # if defined(Q_OS_SOLARIS) && (_POSIX_C_SOURCE - 0 < 199506L) - tmpPw = getpwnam_r(userName.constData(), &pw, buf, bufSize); + tmpPw = getpwnam_r(userName.constData(), &pw, buf.data(), buf.size()); # else - err = getpwnam_r(userName.constData(), &pw, buf, bufSize, &tmpPw); + err = getpwnam_r(userName.constData(), &pw, buf.data(), buf.size(), &tmpPw); # endif if (err || !tmpPw) return path; |