summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2024-07-22 09:35:39 +0200
committerMarc Mutz <[email protected]>2024-08-03 12:30:05 +0200
commitb2b0a5df25c32c3c36c731e2f5ca092edc2c8385 (patch)
treeecb01373b4f278f1c1afccdc4462db077d0c4331
parent7e2fa57faf230ef8cb505b95c2bc0e70867ac131 (diff)
QtGui: port away from q(v)snprintf() and mark the module free of it
No format-string warnings here, thankfully. Pick-to: 6.8 Change-Id: Ib901550ca5e532247635afd995d560dc81628863 Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r--src/gui/CMakeLists.txt1
-rw-r--r--src/gui/image/qxbmhandler.cpp9
-rw-r--r--src/gui/painting/qpdf.cpp41
-rw-r--r--src/gui/rhi/qrhid3d11.cpp4
-rw-r--r--src/gui/rhi/qrhid3d12.cpp2
5 files changed, 32 insertions, 25 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index 3b3dbd13218..124e2bfa293 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -275,6 +275,7 @@ qt_internal_add_module(Gui
QT_NO_CONTEXTLESS_CONNECT
QT_NO_FOREACH
QT_NO_USING_NAMESPACE
+ QT_NO_QSNPRINTF
QT_USE_NODISCARD_FILE_OPEN
QT_QPA_DEFAULT_PLATFORM_NAME="${QT_QPA_DEFAULT_PLATFORM}"
INCLUDE_DIRECTORIES
diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp
index 74c8d8e70fb..66d365e0379 100644
--- a/src/gui/image/qxbmhandler.cpp
+++ b/src/gui/image/qxbmhandler.cpp
@@ -12,6 +12,9 @@
#include <qvariant.h>
#include <private/qtools_p.h>
#include <private/qimage_p.h>
+
+#include <cstdio>
+
#include <stdio.h>
QT_BEGIN_NAMESPACE
@@ -165,11 +168,11 @@ static bool write_xbm_image(const QImage &sourceImage, QIODevice *device, const
const auto msize = s.size() + 100;
char *buf = new char[msize];
- qsnprintf(buf, msize, "#define %s_width %d\n", s.data(), w);
+ std::snprintf(buf, msize, "#define %s_width %d\n", s.data(), w);
device->write(buf, qstrlen(buf));
- qsnprintf(buf, msize, "#define %s_height %d\n", s.data(), h);
+ std::snprintf(buf, msize, "#define %s_height %d\n", s.data(), h);
device->write(buf, qstrlen(buf));
- qsnprintf(buf, msize, "static char %s_bits[] = {\n ", s.data());
+ std::snprintf(buf, msize, "static char %s_bits[] = {\n ", s.data());
device->write(buf, qstrlen(buf));
if (image.format() != QImage::Format_MonoLSB)
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp
index 935d99e4a68..b1fdd7c1222 100644
--- a/src/gui/painting/qpdf.cpp
+++ b/src/gui/painting/qpdf.cpp
@@ -24,6 +24,7 @@
#include <quuid.h>
#include <qxmlstream.h>
+#include <cstdio>
#include <map>
#ifndef QT_NO_COMPRESS
@@ -1750,30 +1751,30 @@ void QPdfEnginePrivate::writeInfo(const QDateTime &date)
constexpr size_t formattedDateSize = 26;
char formattedDate[formattedDateSize];
const int year = qBound(0, d.year(), 9999); // ASN.1, max 4 digits
- auto printedSize = qsnprintf(formattedDate,
- formattedDateSize,
- "(D:%04d%02d%02d%02d%02d%02d",
- year,
- d.month(),
- d.day(),
- t.hour(),
- t.minute(),
- t.second());
+ auto printedSize = std::snprintf(formattedDate,
+ formattedDateSize,
+ "(D:%04d%02d%02d%02d%02d%02d",
+ year,
+ d.month(),
+ d.day(),
+ t.hour(),
+ t.minute(),
+ t.second());
const int offset = date.offsetFromUtc();
const int hours = (offset / 60) / 60;
const int mins = (offset / 60) % 60;
if (offset < 0) {
- qsnprintf(formattedDate + printedSize,
- formattedDateSize - printedSize,
- "-%02d'%02d')", -hours, -mins);
+ std::snprintf(formattedDate + printedSize,
+ formattedDateSize - printedSize,
+ "-%02d'%02d')", -hours, -mins);
} else if (offset > 0) {
- qsnprintf(formattedDate + printedSize,
- formattedDateSize - printedSize,
- "+%02d'%02d')", hours, mins);
+ std::snprintf(formattedDate + printedSize,
+ formattedDateSize - printedSize,
+ "+%02d'%02d')", hours, mins);
} else {
- qsnprintf(formattedDate + printedSize,
- formattedDateSize - printedSize,
- "Z)");
+ std::snprintf(formattedDate + printedSize,
+ formattedDateSize - printedSize,
+ "Z)");
}
write("\n/CreationDate ");
@@ -2472,7 +2473,7 @@ void QPdfEnginePrivate::xprintf(const char* fmt, ...)
va_list args;
va_start(args, fmt);
- int bufsize = qvsnprintf(buf, msize, fmt, args);
+ int bufsize = std::vsnprintf(buf, msize, fmt, args);
va_end(args);
if (Q_LIKELY(bufsize < msize)) {
@@ -2481,7 +2482,7 @@ void QPdfEnginePrivate::xprintf(const char* fmt, ...)
// Fallback for abnormal cases
QScopedArrayPointer<char> tmpbuf(new char[bufsize + 1]);
va_start(args, fmt);
- bufsize = qvsnprintf(tmpbuf.data(), bufsize + 1, fmt, args);
+ bufsize = std::vsnprintf(tmpbuf.data(), bufsize + 1, fmt, args);
va_end(args);
stream->writeRawData(tmpbuf.data(), bufsize);
}
diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp
index ab1d6168b50..fd0ca51f10c 100644
--- a/src/gui/rhi/qrhid3d11.cpp
+++ b/src/gui/rhi/qrhid3d11.cpp
@@ -10,6 +10,8 @@
#include <QtCore/private/qsystemerror_p.h>
#include "qrhid3dhelpers_p.h"
+#include <cstdio>
+
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
@@ -4704,7 +4706,7 @@ bool QD3D11GraphicsPipeline::create()
} else {
QByteArray sem;
sem.resize(16);
- qsnprintf(sem.data(), sem.size(), "TEXCOORD%d_", it->location() - matrixSlice);
+ std::snprintf(sem.data(), sem.size(), "TEXCOORD%d_", it->location() - matrixSlice);
matrixSliceSemantics.append(sem);
desc.SemanticName = matrixSliceSemantics.last().constData();
desc.SemanticIndex = UINT(matrixSlice);
diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp
index 4b593abcb50..c317539e014 100644
--- a/src/gui/rhi/qrhid3d12.cpp
+++ b/src/gui/rhi/qrhid3d12.cpp
@@ -5710,7 +5710,7 @@ bool QD3D12GraphicsPipeline::create()
} else {
QByteArray sem;
sem.resize(16);
- qsnprintf(sem.data(), sem.size(), "TEXCOORD%d_", it->location() - matrixSlice);
+ std::snprintf(sem.data(), sem.size(), "TEXCOORD%d_", it->location() - matrixSlice);
matrixSliceSemantics.append(sem);
desc.SemanticName = matrixSliceSemantics.last().constData();
desc.SemanticIndex = UINT(matrixSlice);