diff --git a/src/burp/BurpTasks.cpp b/src/burp/BurpTasks.cpp index 396e1d7ea53..96376ab5aef 100644 --- a/src/burp/BurpTasks.cpp +++ b/src/burp/BurpTasks.cpp @@ -822,7 +822,7 @@ void RestoreRelationTask::verbRecs(FB_UINT64& records, bool total) void RestoreRelationTask::verbRecsFinal() { - if (m_verbRecs < m_records) + if (m_verbRecs < static_cast(m_records)) { m_verbRecs = m_records; BURP_verbose(107, SafeArg() << m_verbRecs); diff --git a/src/burp/restore.epp b/src/burp/restore.epp index f992afd2b2e..c157be66114 100644 --- a/src/burp/restore.epp +++ b/src/burp/restore.epp @@ -12365,7 +12365,7 @@ bool RestoreRelationTask::fileReader(Item& item) const FB_SSIZE_T attLen = 1 + (tdgbl->gbl_sw_transportable ? 12 : 6); const FB_SSIZE_T overhead = tdgbl->gbl_sw_compress ? (len / 127 + 1) : 0; - if (len + attLen + overhead > space) + if (static_cast(len) + attLen + overhead > space) { if (ioBuf) { diff --git a/src/common/CvtFormat.cpp b/src/common/CvtFormat.cpp index c0485e20871..301c1e25fb2 100644 --- a/src/common/CvtFormat.cpp +++ b/src/common/CvtFormat.cpp @@ -141,9 +141,9 @@ namespace InitInstance timeZoneTrie; - #define CVT_FORMAT(id, format) constexpr Patterns format = 1llu << id - 1; - #define CVT_FORMAT2(id, format1, format2) constexpr Patterns format2 = 1llu << id - 1; - #define CVT_FORMAT_FLAG(id, format) constexpr Patterns format = 1llu << id - 1; + #define CVT_FORMAT(id, format) constexpr Patterns format = 1llu << (id - 1); + #define CVT_FORMAT2(id, format1, format2) constexpr Patterns format2 = 1llu << (id - 1); + #define CVT_FORMAT_FLAG(id, format) constexpr Patterns format = 1llu << (id - 1); namespace Format { typedef FB_UINT64 Patterns; @@ -343,7 +343,7 @@ namespace if (number < 1 || number > 9) return Format::NONE; - return Format::FF1 << number - 1; + return Format::FF1 << (number - 1); } break; diff --git a/src/common/unicode_util.cpp b/src/common/unicode_util.cpp index ce9ffd31cf6..fb55773d367 100644 --- a/src/common/unicode_util.cpp +++ b/src/common/unicode_util.cpp @@ -1615,7 +1615,7 @@ UnicodeUtil::Utf16Collation* UnicodeUtil::Utf16Collation::create( if (len >= 2) { - obj->maxContractionsPrefixLength = len - 1 > obj->maxContractionsPrefixLength ? + obj->maxContractionsPrefixLength = static_cast(len - 1) > obj->maxContractionsPrefixLength ? len - 1 : obj->maxContractionsPrefixLength; UCHAR key[100]; @@ -1865,7 +1865,7 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src lastCharKeyLen = icu->ucolGetSortKey(coll, reinterpret_cast(src + srcLenLong), i, lastCharKey, sizeof(lastCharKey)); - if (prefixLen == 0 || prefixLen > dstLen - 2 || prefixLen > MAX_USHORT || + if (prefixLen == 0 || prefixLen > dstLen - 2u || prefixLen > MAX_USHORT || lastCharKeyLen == 0) { return INTL_BAD_KEY_LENGTH; @@ -1895,7 +1895,7 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src const ULONG keyLen = prefixLen + keyIt.getCount() - advance; - if (keyLen > dstLen - 2 || keyLen > MAX_USHORT) + if (keyLen > dstLen - 2u || keyLen > MAX_USHORT) return INTL_BAD_KEY_LENGTH; dst[0] = UCHAR(keyLen & 0xFF); @@ -1920,7 +1920,7 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src ULONG keyLen = icu->ucolGetSortKey(coll, reinterpret_cast(src), srcLenLong, originalDst + 2, originalDstLen - 3); - if (keyLen == 0 || keyLen > originalDstLen - 3 || keyLen > MAX_USHORT) + if (keyLen == 0 || keyLen > originalDstLen - 3u || keyLen > MAX_USHORT) return INTL_BAD_KEY_LENGTH; fb_assert(originalDst[2 + keyLen - 1] == '\0'); diff --git a/src/dsql/BoolNodes.cpp b/src/dsql/BoolNodes.cpp index 38975713c5a..b75c55b2c3b 100644 --- a/src/dsql/BoolNodes.cpp +++ b/src/dsql/BoolNodes.cpp @@ -1058,7 +1058,7 @@ bool ComparativeBoolNode::stringBoolean(thread_db* tdbb, Request* request, dsc* cache->matcher->reset(); else { - if (cache && cache->keySize < patternLen + escapeLen) + if (cache && cache->keySize < static_cast(patternLen) + escapeLen) { delete cache; cache = nullptr; diff --git a/src/dsql/ExprNodes.cpp b/src/dsql/ExprNodes.cpp index 8320ab355be..0e8ffea89b3 100644 --- a/src/dsql/ExprNodes.cpp +++ b/src/dsql/ExprNodes.cpp @@ -12182,11 +12182,11 @@ dsc* SubstringSimilarNode::execute(thread_db* tdbb, Request* request) const MoveBuffer patternBuffer; UCHAR* patternStr; - int patternLen = MOV_make_string2(tdbb, patternDesc, textType, &patternStr, patternBuffer); + ULONG patternLen = MOV_make_string2(tdbb, patternDesc, textType, &patternStr, patternBuffer); MoveBuffer escapeBuffer; UCHAR* escapeStr; - int escapeLen = MOV_make_string2(tdbb, escapeDesc, textType, &escapeStr, escapeBuffer); + ULONG escapeLen = MOV_make_string2(tdbb, escapeDesc, textType, &escapeStr, escapeBuffer); // Verify the correctness of the escape character. if (escapeLen == 0 || charSet->length(escapeLen, escapeStr, true) != 1) diff --git a/src/dsql/StmtNodes.cpp b/src/dsql/StmtNodes.cpp index 3252da179b1..e54886aa179 100644 --- a/src/dsql/StmtNodes.cpp +++ b/src/dsql/StmtNodes.cpp @@ -3428,7 +3428,7 @@ ExecProcedureNode* ExecProcedureNode::dsqlPass(DsqlCompilerScratch* dsqlScratch) const auto positionalArgCount = inputSources->items.getCount() - (dsqlInputArgNames ? dsqlInputArgNames->getCount() : 0); - if (positionalArgCount > procedure->prc_in_count || dsqlInputArgNames) + if (static_cast(positionalArgCount) > procedure->prc_in_count || dsqlInputArgNames) { const auto newInputs = FB_NEW_POOL(pool) ValueListNode(pool); const auto newOutputs = FB_NEW_POOL(pool) ValueListNode(pool); @@ -3443,7 +3443,7 @@ ExecProcedureNode* ExecProcedureNode::dsqlPass(DsqlCompilerScratch* dsqlScratch) for (auto source : inputSources->items) { - const bool isInput = (pos < positionalArgCount && pos < procedure->prc_in_count) || + const bool isInput = (pos < positionalArgCount && pos < static_cast(procedure->prc_in_count)) || (pos >= positionalArgCount && !outFields.exist((*dsqlInputArgNames)[pos - positionalArgCount])); diff --git a/src/include/firebird/iberror.h b/src/include/firebird/iberror.h index 5e6446f1365..da72cb48afe 100644 --- a/src/include/firebird/iberror.h +++ b/src/include/firebird/iberror.h @@ -17,32 +17,38 @@ #ifdef __cplusplus /* c++ definitions */ -const ISC_STATUS isc_facility = 20; -const ISC_STATUS isc_base = isc_facility << 24; -const ISC_STATUS isc_factor = 1; - -const ISC_STATUS isc_arg_end = 0; // end of argument list -const ISC_STATUS isc_arg_gds = 1; // generic DSRI status value -const ISC_STATUS isc_arg_string = 2; // string argument -const ISC_STATUS isc_arg_cstring = 3; // count & string argument -const ISC_STATUS isc_arg_number = 4; // numeric argument (long) -const ISC_STATUS isc_arg_interpreted = 5; // interpreted status code (string) -const ISC_STATUS isc_arg_vms = 6; // VAX/VMS status code (long) -const ISC_STATUS isc_arg_unix = 7; // UNIX error code -const ISC_STATUS isc_arg_domain = 8; // Apollo/Domain error code -const ISC_STATUS isc_arg_dos = 9; // MSDOS/OS2 error code -const ISC_STATUS isc_arg_mpexl = 10; // HP MPE/XL error code -const ISC_STATUS isc_arg_mpexl_ipc = 11; // HP MPE/XL IPC error code -const ISC_STATUS isc_arg_next_mach = 15; // NeXT/Mach error code -const ISC_STATUS isc_arg_netware = 16; // NetWare error code -const ISC_STATUS isc_arg_win32 = 17; // Win32 error code -const ISC_STATUS isc_arg_warning = 18; // warning argument -const ISC_STATUS isc_arg_sql_state = 19; // SQLSTATE +#if __cplusplus >= 201703L // C++17 or later +#define STATUS_EXPR inline constexpr ISC_STATUS +#else +#define STATUS_EXPR const ISC_STATUS +#endif + +STATUS_EXPR isc_facility = 20; +STATUS_EXPR isc_base = isc_facility << 24; +STATUS_EXPR isc_factor = 1; + +STATUS_EXPR isc_arg_end = 0; // end of argument list +STATUS_EXPR isc_arg_gds = 1; // generic DSRI status value +STATUS_EXPR isc_arg_string = 2; // string argument +STATUS_EXPR isc_arg_cstring = 3; // count & string argument +STATUS_EXPR isc_arg_number = 4; // numeric argument (long) +STATUS_EXPR isc_arg_interpreted = 5; // interpreted status code (string) +STATUS_EXPR isc_arg_vms = 6; // VAX/VMS status code (long) +STATUS_EXPR isc_arg_unix = 7; // UNIX error code +STATUS_EXPR isc_arg_domain = 8; // Apollo/Domain error code +STATUS_EXPR isc_arg_dos = 9; // MSDOS/OS2 error code +STATUS_EXPR isc_arg_mpexl = 10; // HP MPE/XL error code +STATUS_EXPR isc_arg_mpexl_ipc = 11; // HP MPE/XL IPC error code +STATUS_EXPR isc_arg_next_mach = 15; // NeXT/Mach error code +STATUS_EXPR isc_arg_netware = 16; // NetWare error code +STATUS_EXPR isc_arg_win32 = 17; // Win32 error code +STATUS_EXPR isc_arg_warning = 18; // warning argument +STATUS_EXPR isc_arg_sql_state = 19; // SQLSTATE #define FB_IMPL_MSG_NO_SYMBOL(facility, number, text) #define FB_IMPL_MSG_SYMBOL(facility, number, symbol, text) \ - const ISC_STATUS isc_##symbol = FB_IMPL_MSG_ENCODE(number, FB_IMPL_MSG_FACILITY_##facility); + STATUS_EXPR isc_##symbol = FB_IMPL_MSG_ENCODE(number, FB_IMPL_MSG_FACILITY_##facility); #define FB_IMPL_MSG(facility, number, symbol, sqlCode, sqlClass, sqlSubClass, text) \ FB_IMPL_MSG_SYMBOL(facility, number, symbol, text) @@ -53,7 +59,7 @@ const ISC_STATUS isc_arg_sql_state = 19; // SQLSTATE #undef FB_IMPL_MSG_SYMBOL #undef FB_IMPL_MSG -const ISC_STATUS isc_err_max = 0 +STATUS_EXPR isc_err_max = 0 #define FB_IMPL_MSG_NO_SYMBOL(facility, number, text) #define FB_IMPL_MSG_SYMBOL(facility, number, symbol, text) #define FB_IMPL_MSG(facility, number, symbol, sqlCode, sqlClass, sqlSubClass, text) + 1 diff --git a/src/isql/FrontendLexer.cpp b/src/isql/FrontendLexer.cpp index 5c5a63d911d..3a6adab5e96 100644 --- a/src/isql/FrontendLexer.cpp +++ b/src/isql/FrontendLexer.cpp @@ -142,7 +142,7 @@ std::variant= term.length() && std::equal(term.begin(), term.end(), pos)) + if (static_cast(end - pos) >= term.length() && std::equal(term.begin(), term.end(), pos)) { const auto initialStatement = std::string(buffer.cbegin(), pos); pos += term.length(); diff --git a/src/isql/isql.h b/src/isql/isql.h index 8c97ec42a8e..6a63bb0794c 100644 --- a/src/isql/isql.h +++ b/src/isql/isql.h @@ -111,7 +111,7 @@ const int ISQL_MSG_FAC = FB_IMPL_MSG_FACILITY_ISQL; #define FB_IMPL_MSG_NO_SYMBOL(facility, number, text) #define FB_IMPL_MSG_SYMBOL(facility, number, symbol, text) \ - const int symbol = number; + inline constexpr int symbol = number; #define FB_IMPL_MSG(facility, number, symbol, sqlCode, sqlClass, sqlSubClass, text) \ FB_IMPL_MSG_SYMBOL(facility, number, symbol, text) diff --git a/src/jrd/ExtEngineManager.cpp b/src/jrd/ExtEngineManager.cpp index 8f28a59fcc3..862662845bb 100644 --- a/src/jrd/ExtEngineManager.cpp +++ b/src/jrd/ExtEngineManager.cpp @@ -318,7 +318,7 @@ namespace checkMessageEof(aCheckMessageEof) { // Iterate over the format items, except the EOF item. - for (unsigned i = 0; i < (fromMessage->format->fmt_count / 2) * 2; i += 2) + for (unsigned i = 0; i < (fromMessage->format->fmt_count / 2u) * 2u; i += 2) { auto flag = FB_NEW_POOL(pool) ParameterNode(pool); flag->messageNumber = fromMessage->messageNumber; diff --git a/src/jrd/idx.cpp b/src/jrd/idx.cpp index 5c22b9b1862..ce7003ad9e4 100644 --- a/src/jrd/idx.cpp +++ b/src/jrd/idx.cpp @@ -808,7 +808,7 @@ bool IndexCreateTask::getResult(IStatus* status) int IndexCreateTask::getMaxWorkers() { - const int parWorkers = m_items.getCount(); + const FB_SIZE_T parWorkers = m_items.getCount(); if (parWorkers == 1 || m_countPP == 0) return 1; diff --git a/src/jrd/inf.cpp b/src/jrd/inf.cpp index cdac0eeb5a8..370fa35ceff 100644 --- a/src/jrd/inf.cpp +++ b/src/jrd/inf.cpp @@ -785,7 +785,7 @@ void INF_database_info(thread_db* tdbb, length = gds__vax_integer(items, 2); items += 2; - if (end_items - items >= length) + if (static_cast(end_items - items) >= length) { pageNum = gds__vax_integer(items, length); items += length; diff --git a/src/jrd/sqz.cpp b/src/jrd/sqz.cpp index c366b7ebe74..d1d6e5f6e07 100644 --- a/src/jrd/sqz.cpp +++ b/src/jrd/sqz.cpp @@ -76,7 +76,7 @@ unsigned Compressor::nonCompressableRun(unsigned length) if (m_runs.hasData() && m_runs.back() > 0 && m_runs.back() < MAX_NONCOMP_RUN) { - const auto max = MIN(MAX_NONCOMP_RUN - m_runs.back(), length); + const auto max = MIN(static_cast(MAX_NONCOMP_RUN - m_runs.back()), length); length -= max; m_runs.back() += max; } @@ -558,7 +558,7 @@ ULONG Difference::apply(ULONG diffLength, ULONG outLength, UCHAR* const output) BUGCHECK(177); // msg 177 applied differences will not fit in record } - const auto length = p - output; + const FB_UINT64 length = p - output; if (length > outLength) BUGCHECK(177); // msg 177 applied differences will not fit in record diff --git a/src/yvalve/why.cpp b/src/yvalve/why.cpp index cc722930c2b..f4777497b30 100644 --- a/src/yvalve/why.cpp +++ b/src/yvalve/why.cpp @@ -1424,7 +1424,7 @@ static void setTextType(XSQLVAR* var, unsigned charSet) static int sqldaTruncateString(char* buffer, FB_SIZE_T size, const char* s) { int ret = fb_utils::snprintf(buffer, size, "%s", s); - return MIN(ret, size - 1); + return MIN(ret, static_cast(size - 1)); } // Describe parameters metadata in an sqlda.