get rid of qvsnprintf() and qsnprintf() [ci reset]

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-09-07 19:58:41 +03:00
parent ce935b34d5
commit 20090b989a
18 changed files with 27 additions and 110 deletions

View file

@ -384,13 +384,13 @@ JSValue QT_FASTCALL globalFuncEscape(ExecState* exec, JSObject*, JSValue, const
int u = c[0];
if (u > 255) {
char tmp[7];
sprintf(tmp, "%%u%04X", u);
::snprintf(tmp, sizeof(tmp), "%%u%04X", u);
s = UString(tmp);
} else if (u != 0 && strchr(do_not_escape, static_cast<char>(u)))
s = UString(c, 1);
else {
char tmp[4];
sprintf(tmp, "%%%02X", u);
::snprintf(tmp, sizeof(tmp), "%%%02X", u);
s = UString(tmp);
}
builder.append(s);

View file

@ -147,7 +147,7 @@ UString UString::from(int i)
*--p = '0';
else if (i == INT_MIN) {
char minBuf[1 + sizeof(i) * 3];
sprintf(minBuf, "%d", INT_MIN);
::snprintf(minBuf, sizeof(minBuf), "%d", INT_MIN);
return UString(minBuf);
} else {
bool negative = false;
@ -223,7 +223,7 @@ UString UString::from(long l)
*--p = '0';
else if (l == LONG_MIN) {
char minBuf[1 + sizeof(l) * 3];
sprintf(minBuf, "%ld", LONG_MIN);
::snprintf(minBuf, sizeof(minBuf), "%ld", LONG_MIN);
return UString(minBuf);
} else {
bool negative = false;

View file

@ -394,7 +394,6 @@ set(CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/tools/qtextboundaryfinder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tools/qtimeline.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tools/qvector.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tools/qvsnprintf.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tools/qelapsedtimer_unix.cpp
)

View file

@ -1174,7 +1174,7 @@ static void qt_message(QtMsgType msgType, const char *format, va_list ap)
{
if (Q_LIKELY(format)) {
QSTACKARRAY(char, messagebuf, 1024);
qvsnprintf(messagebuf, sizeof(messagebuf), format, ap);
::vsnprintf(messagebuf, sizeof(messagebuf), format, ap);
qt_message_output(msgType, messagebuf);
}
}

View file

@ -80,7 +80,7 @@ static inline QByteArray qt_prettyDebug(const char *data, int len, int maxSize)
case '\t': out += "\\t"; break;
default:
QSTACKARRAY(char, buf, 5);
qsnprintf(buf, sizeof(buf), "\\%3o", c);
::snprintf(buf, sizeof(buf), "\\%3o", c);
buf[4] = '\0';
out += QByteArray(buf);
}

View file

@ -27,7 +27,6 @@
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <string>
QT_BEGIN_NAMESPACE
@ -70,12 +69,6 @@ inline int qstrnicmp(const char *str1, const char *str2, uint len)
: (str1 ? 1 : (str2 ? -1 : 0));
}
// implemented in qvsnprintf.cpp
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...);
inline int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
{ return ::vsnprintf(str, n, fmt, ap); }
// qChecksum: Internet checksum
Q_CORE_EXPORT quint16 qChecksum(const char *s, uint len);

View file

@ -323,13 +323,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------
*/
// the code bellow is copy from musl libc, modified to not use static buffer
// and use snprintf() instead of sprintf()
char *qfcvt(double x, int n, int *dp, int *sign, char* buf)
{
QSTACKARRAY(char, tmp, 1500);
int i, lz;
if (n > 1400) n = 1400;
sprintf(tmp, "%.*f", n, x);
::snprintf(tmp, sizeof(tmp), "%.*f", n, x);
i = (tmp[0] == '-');
if (tmp[i] == '0') lz = strspn(tmp+i+2, "0");
else lz = -(int)strcspn(tmp+i, ".");
@ -350,7 +351,7 @@ char *qecvt(double x, int n, int *dp, int *sign, char* buf)
int i, j;
if (n-1 > 15) n = 15;
sprintf(tmp, "%.*e", n-1, x);
::snprintf(tmp, sizeof(tmp), "%.*e", n-1, x);
i = *sign = (tmp[0]=='-');
for (j=0; tmp[i]!='e'; j+=(tmp[i++]!='.'))
buf[j] = tmp[i];

View file

@ -4420,7 +4420,7 @@ QString &QString::sprintf(const char *cformat, ...)
{
va_list ap;
va_start(ap, cformat);
QString &s = vsprintf(cformat, ap);
QString &s = QString::vsprintf(cformat, ap);
va_end(ap);
return s;
}

View file

@ -1,76 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2016 Ivailo Monev
**
** This file is part of the QtCore module of the Katie Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qbytearray.h"
#include "qstring.h"
QT_BEGIN_NAMESPACE
/*!
\fn return qvsnprintf(str, n, fmt, ap);
\relates QByteArray
A portable \c vsnprintf() function. Will call \c ::vsnprintf(), \c
::_vsnprintf(), or \c ::vsnprintf_s depending on the system, or
fall back to an internal version.
\a fmt is the \c printf() format string. The result is put into
\a str, which is a buffer of at least \a n bytes.
The caller is responsible to call \c va_end() on \a ap.
\warning Since vsnprintf() shows different behavior on certain
platforms, you should not rely on the return value or on the fact
that you will always get a 0 terminated string back.
Ideally, you should never call this function but use QString::sprintf()
instead.
\sa qsnprintf(), QString::sprintf()
*/
/*!
\relates QByteArray
A portable snprintf() function, calls qvsnprintf.
\a fmt is the \c printf() format string. The result is put into
\a str, which is a buffer of at least \a n bytes.
\warning Call this function only when you know what you are doing
since it shows different behavior on certain platforms.
Use QString::sprintf() to format a string instead.
\sa qvsnprintf(), QString::sprintf()
*/
int qsnprintf(char *str, size_t n, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int ret = qvsnprintf(str, n, fmt, ap);
va_end(ap);
return ret;
}
QT_END_NAMESPACE

View file

@ -169,11 +169,11 @@ static bool write_xbm_image(const QImage &sourceImage, QIODevice *device, const
int msize = fileName.length() + 100;
QSTACKARRAY(char, buf, msize);
qsnprintf(buf, msize, "#define %s_width %d\n", fileName.toAscii().data(), w);
::snprintf(buf, msize, "#define %s_width %d\n", fileName.toAscii().data(), w);
device->write(buf, qstrlen(buf));
qsnprintf(buf, msize, "#define %s_height %d\n", fileName.toAscii().data(), h);
::snprintf(buf, msize, "#define %s_height %d\n", fileName.toAscii().data(), h);
device->write(buf, qstrlen(buf));
qsnprintf(buf, msize, "static char %s_bits[] = {\n ", fileName.toAscii().data());
::snprintf(buf, msize, "static char %s_bits[] = {\n ", fileName.toAscii().data());
device->write(buf, qstrlen(buf));
if (image.format() != QImage::Format_MonoLSB)

View file

@ -435,7 +435,7 @@ static int qt_x_errhandler(Display *dpy, XErrorEvent *err)
XGetErrorText(dpy, err->error_code, errstr, maxerrlen);
QSTACKARRAY(char, buffer, maxerrlen);
QSTACKARRAY(char, request_str, maxerrlen);
qsnprintf(buffer, maxerrlen, "%d", err->request_code);
::snprintf(buffer, maxerrlen, "%d", err->request_code);
XGetErrorDatabaseText(dpy, "XRequest", buffer, "", request_str, maxerrlen);
if (err->request_code < 128) {
// X error for a normal protocol request
@ -456,11 +456,11 @@ static int qt_x_errhandler(Display *dpy, XErrorEvent *err)
QSTACKARRAY(char, minor_str, maxerrlen);
if (extensionName) {
qsnprintf(buffer, maxerrlen, "%s.%d", extensionName, err->minor_code);
::snprintf(buffer, maxerrlen, "%s.%d", extensionName, err->minor_code);
XGetErrorDatabaseText(dpy, "XRequest", buffer, "", minor_str, maxerrlen);
} else {
extensionName = "Unknown extension";
qsnprintf(minor_str, maxerrlen, "Unknown request");
::snprintf(minor_str, maxerrlen, "Unknown request");
}
qWarning( "X Error: %s %d\n"
" Extension: %d (%s)\n"

View file

@ -643,9 +643,9 @@ QColor::QColor(Spec spec)
QString QColor::name() const
{
QSTACKARRAY(char, sprintfbuf, 8);
qsnprintf(sprintfbuf, sizeof(sprintfbuf), "#%02x%02x%02x", red(), green(), blue());
return QString::fromLatin1(sprintfbuf);
QSTACKARRAY(char, snprintfbuf, 8);
::snprintf(snprintfbuf, sizeof(snprintfbuf), "#%02x%02x%02x", red(), green(), blue());
return QString::fromLatin1(snprintfbuf);
}
/*!

View file

@ -704,7 +704,7 @@ void QPdfEnginePrivate::xprintf(const char* fmt, ...)
va_list args;
va_start(args, fmt);
int bufsize = qvsnprintf(buf, msize, fmt, args);
int bufsize = ::vsnprintf(buf, msize, fmt, args);
Q_ASSERT(bufsize < msize);

View file

@ -670,10 +670,10 @@ QString QHostAddress::toString() const
QT_ENSURE_PARSED(this);
if (d->protocol == QAbstractSocket::IPv4Protocol) {
const quint32 i = toIPv4Address();
QSTACKARRAY(char, sprintfbuf, 20);
qsnprintf(sprintfbuf, sizeof(sprintfbuf), "%d.%d.%d.%d",
QSTACKARRAY(char, snprintfbuf, 20);
::snprintf(snprintfbuf, sizeof(snprintfbuf), "%d.%d.%d.%d",
(i>>24) & 0xff, (i>>16) & 0xff, (i >> 8) & 0xff, i & 0xff);
return QString::fromLatin1(sprintfbuf);
return QString::fromLatin1(snprintfbuf);
}
if (d->protocol == QAbstractSocket::IPv6Protocol) {

View file

@ -111,7 +111,7 @@ QString QNetworkInterfacePrivate::makeHwAddress(int len, uchar *data)
result += QLatin1Char(':');
QSTACKARRAY(char, buf, 3);
sprintf(buf, "%02hX", ushort(data[i]));
::snprintf(buf, sizeof(buf), "%02hX", ushort(data[i]));
result += QString::fromLatin1(buf);
}
return result;

View file

@ -96,7 +96,7 @@ int qt_asprintf(QTestCharBuffer *str, const char *format, ...)
for (;;) {
va_start(ap, format);
res = qvsnprintf(str->data(), size, format, ap);
res = ::vsnprintf(str->data(), size, format, ap);
va_end(ap);
str->data()[size - 1] = '\0';
if (res >= 0 && res < size) {

View file

@ -858,7 +858,7 @@ int qt_snprintf(char *str, int size, const char *format, ...)
int res = 0;
va_start(ap, format);
qvsnprintf(str, size, format, ap);
::vsnprintf(str, size, format, ap);
va_end(ap);
str[size - 1] = '\0';

View file

@ -240,7 +240,7 @@ void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
QTest::benchmarkResultFormatString(),
quotedMetric.constData(),
quotedTag.constData(),
QByteArray::number(result.value).constData(), //no 64-bit qsnprintf support
QByteArray::number(result.value).constData(),
result.iterations);
outputString(buf.constData());
}