From 166753d8e00e11d2fa92d3bfbe5667ad4b8f7b9d Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 7 Mar 2019 16:57:52 +0100 Subject: rcc: Avoid needless use of macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit strlen on literals gets typically optimized out nowadays. Adjust callee side to handle the off-by-one between sizeof(literal) and strlen(). Change-Id: I1551f69a160922681d66024701ba1bd8f6dc03bf Reviewed-by: Jörg Bornemann --- src/tools/rcc/rcc.cpp | 5 +---- src/tools/rcc/rcc.h | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index 08fb6fca5f..94f6911010 100644 --- a/src/tools/rcc/rcc.cpp +++ b/src/tools/rcc/rcc.cpp @@ -67,11 +67,8 @@ enum { # define CONSTANT_COMPRESSALGO_DEFAULT RCCResourceLibrary::CompressionAlgorithm::None #endif -#define writeString(s) write(s, sizeof(s)) - void RCCResourceLibrary::write(const char *str, int len) { - --len; // trailing \0 on string literals... int n = m_out.size(); m_out.resize(n + len); memcpy(m_out.data() + n, str, len); @@ -983,7 +980,7 @@ void RCCResourceLibrary::writeDecimal(int value) Q_ASSERT(m_format != RCCResourceLibrary::Binary); char buf[std::numeric_limits::digits10 + 2]; int n = snprintf(buf, sizeof(buf), "%d", value); - write(buf, n + 1); // write() takes a size including terminating NUL + write(buf, n); } static const char hexDigits[] = "0123456789abcdef"; diff --git a/src/tools/rcc/rcc.h b/src/tools/rcc/rcc.h index b301355e4f..190c37a1f6 100644 --- a/src/tools/rcc/rcc.h +++ b/src/tools/rcc/rcc.h @@ -143,6 +143,7 @@ private: void writeChar(char c) { m_out.append(c); } void writeByteArray(const QByteArray &); void write(const char *, int len); + void writeString(const char *s) { write(s, static_cast(strlen(s))); } #if QT_CONFIG(zstd) ZSTD_CCtx *m_zstdCCtx; -- cgit v1.2.3