From 5a2ee82f2ccb79a9bd8c9309a0ad1532045e79a6 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 17 Mar 2021 12:01:06 +0100 Subject: [PATCH 1/2] Disable security warnings from MSVC in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MSVC generates the following for those tests: warning C4996: '_open': This function or variable may be unsafe. Consider using _sopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. We need to set the define before any C runtime headers are included, so do it right away, it doesn't do any harm on other compilers. Change-Id: Ia25afb87934058c3f27e63820eeb2db063a627f1 Reviewed-by: MÃ¥rten Nordheim --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 2 ++ tests/auto/corelib/io/qipaddress/tst_qipaddress.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index bdfcc2d350..188e3fdc25 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -27,6 +27,8 @@ ** ****************************************************************************/ +#define _CRT_SECURE_NO_WARNINGS 1 + #include #include #include diff --git a/tests/auto/corelib/io/qipaddress/tst_qipaddress.cpp b/tests/auto/corelib/io/qipaddress/tst_qipaddress.cpp index 5f99cec3af..60b0c697c5 100644 --- a/tests/auto/corelib/io/qipaddress/tst_qipaddress.cpp +++ b/tests/auto/corelib/io/qipaddress/tst_qipaddress.cpp @@ -26,6 +26,8 @@ ** ****************************************************************************/ +#define _CRT_SECURE_NO_WARNINGS 1 + #include #include #include From 872f3fffbf712be90a00873a427e6a4149ed4911 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 17 Mar 2021 15:11:22 +0100 Subject: [PATCH 2/2] QSqlError: protect against self-assignment Address static analyzer warning 6eb3060fd64e459b6cd5586dc561e0ba. Also make assignment from a moved-from object safe. Task-number: QTBUG-91912 Change-Id: I732dc244ac0c731a02d85e88023dbd952b9eb112 Reviewed-by: Andy Shaw Reviewed-by: Andrei Golubev --- src/sql/kernel/qsqlerror.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sql/kernel/qsqlerror.cpp b/src/sql/kernel/qsqlerror.cpp index 2f51debdd0..5e69778a2a 100644 --- a/src/sql/kernel/qsqlerror.cpp +++ b/src/sql/kernel/qsqlerror.cpp @@ -151,9 +151,13 @@ QSqlError::QSqlError(const QSqlError& other) QSqlError& QSqlError::operator=(const QSqlError& other) { - if (d) + if (&other == this) + return *this; + if (d && other.d) *d = *other.d; - else + else if (d) + *d = QSqlErrorPrivate(); + else if (other.d) d = new QSqlErrorPrivate(*other.d); return *this; }