Deprecate q(v)snprintf()

[ChangeLog][Deprecation Notice][q(v)snprintf()] As warned in advance
in the 6.8 change-log, these functions have now been deprecated with
immediate effect. Due to an unfortunate fallback to
QString::asprintf().toLocal8Bit(), these functions introduce strictly
more platform dependencies than C++11's std::(v)snprintf(), which is
the suggested replacement.

Fixes: QTBUG-127110
Change-Id: Ieee4149ac6c4a9881e1445a77e62edd92c71b36c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2024-07-31 21:05:04 +02:00
parent 73d7138c02
commit afd0bb28fb
3 changed files with 25 additions and 6 deletions

View File

@ -139,11 +139,21 @@ Q_CORE_EXPORT int qstrnicmp(const char *, const char *, size_t len);
Q_CORE_EXPORT int qstrnicmp(const char *, qsizetype, const char *, qsizetype = -1);
#ifndef QT_NO_QSNPRINTF // use std::(v)snprintf() from <cstdio> instead
#if QT_DEPRECATED_SINCE(6, 9)
#define QSNPF_DEPR(vsn) \
QT_DEPRECATED_VERSION_X_6_9("Use C++11 std::" #vsn "printf() instead, taking care to " \
"ensure that you didn't rely on QString::asprintf() " \
"ideosyncrasies that q" #vsn "printf might, but " \
"std::" #vsn "printf() does not, support.")
// implemented in qvsnprintf.cpp
QSNPF_DEPR(vsn)
Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
Q_ATTRIBUTE_FORMAT_PRINTF(3, 0);
QSNPF_DEPR(sn)
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...)
Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
#undef QSNPF_DEPR
#endif // QT_DEPRECATED_SINCE(6, 9)
#endif // QT_NO_QSNPRINTF
// qChecksum: Internet checksum

View File

@ -22,15 +22,15 @@ QT_BEGIN_NAMESPACE
\sa qsnprintf(), qvsnprintf().
*/
#if QT_DEPRECATED_SINCE(6, 9)
#if !defined(QT_VSNPRINTF) || defined(Q_QDOC)
/*!
\fn int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
\relates QByteArray
\obsolete
Use C++11's \c{std::vsnprintf()} from \c{<cstdio>} instead.
\deprecated [6.9] Use C++11's \c{std::vsnprintf()} from \c{<cstdio>} instead.
A portable \c vsnprintf() function. Will call \c ::vsnprintf(), \c
::_vsnprintf(), or \c ::vsnprintf_s depending on the system, or
@ -89,9 +89,7 @@ int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
\target bytearray-qsnprintf
\relates QByteArray
\obsolete
Use C++11's \c{std::snprintf()} from \c{<cstdio>} instead.
\deprecated [6.9] Use C++11's \c{std::snprintf()} from \c{<cstdio>} instead.
A portable snprintf() function, calls qvsnprintf.
@ -111,10 +109,14 @@ int qsnprintf(char *str, size_t n, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
QT_IGNORE_DEPRECATIONS(
int ret = qvsnprintf(str, n, fmt, ap);
)
va_end(ap);
return ret;
}
#endif // QT_DEPRECATED_SINCE(6, 9)
QT_END_NAMESPACE

View File

@ -40,7 +40,9 @@ private slots:
void base64();
void fromBase64_data();
void fromBase64();
#if QT_DEPRECATED_SINCE(6, 9)
void qvsnprintf();
#endif
void qstrlen();
void qstrnlen();
void qstrcpy();
@ -679,6 +681,9 @@ void tst_QByteArray::fromBase64()
}
}
#if QT_DEPRECATED_SINCE(6, 9)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
void tst_QByteArray::qvsnprintf()
{
char buf[20];
@ -723,6 +728,8 @@ void tst_QByteArray::qvsnprintf()
QT_WARNING_POP
#endif
}
QT_WARNING_POP
#endif // QT_DEPRECATED_SINCE(6, 9)
void tst_QByteArray::qstrlen()