diff --git a/src/common/CvtFormat.cpp b/src/common/CvtFormat.cpp index 3ceb1c256e4..92c303cd151 100644 --- a/src/common/CvtFormat.cpp +++ b/src/common/CvtFormat.cpp @@ -1331,7 +1331,7 @@ namespace bool isFound = false; std::string_view monthShortName = getSubstringFromString(str, strLength, strOffset, 3); - for (int i = 0; i < FB_NELEM(FB_SHORT_MONTHS) - 1; i++) + for (FB_SIZE_T i = 0; i < FB_NELEM(FB_SHORT_MONTHS) - 1; i++) { if (std::equal(monthShortName.begin(), monthShortName.end(), FB_SHORT_MONTHS[i], FB_SHORT_MONTHS[i] + strlen(FB_SHORT_MONTHS[i]), @@ -1352,7 +1352,7 @@ namespace bool isFound = false; std::string_view monthFullName = getSubstringFromString(str, strLength, strOffset); - for (int i = 0; i < FB_NELEM(FB_LONG_MONTHS_UPPER) - 1; i++) + for (FB_SIZE_T i = 0; i < FB_NELEM(FB_LONG_MONTHS_UPPER) - 1; i++) { if (std::equal(monthFullName.begin(), monthFullName.end(), FB_LONG_MONTHS_UPPER[i], FB_LONG_MONTHS_UPPER[i] + strlen(FB_LONG_MONTHS_UPPER[i]), diff --git a/src/common/SimilarToRegex.cpp b/src/common/SimilarToRegex.cpp index 42d07091333..b1b30ed0b4d 100644 --- a/src/common/SimilarToRegex.cpp +++ b/src/common/SimilarToRegex.cpp @@ -410,7 +410,7 @@ namespace if (!hasPatternChar() || getPatternChar() != ']') status_exception::raise(Arg::Gds(isc_invalid_similar_pattern)); - for (item.clazz = 0; item.clazz < FB_NELEM(classes); ++item.clazz) + for (item.clazz = 0; static_cast(item.clazz) < FB_NELEM(classes); ++item.clazz) { if (fb_utils::strnicmp(patternStr + charSavePos, classes[item.clazz].similarClass, len) == 0) @@ -419,7 +419,7 @@ namespace } } - if (item.clazz >= FB_NELEM(classes)) + if (static_cast(item.clazz) >= FB_NELEM(classes)) status_exception::raise(Arg::Gds(isc_invalid_similar_pattern)); } else diff --git a/src/common/TextType.cpp b/src/common/TextType.cpp index ae095b4a2e1..4d8353655e3 100644 --- a/src/common/TextType.cpp +++ b/src/common/TextType.cpp @@ -153,7 +153,7 @@ TextType::TextType(TTYPE_ID _type, texttype *_tt, USHORT _attributes, CharSet* _ {'S', CHAR_UPPER_S} }; - for (int i = 0; i < FB_NELEM(conversions); i++) + for (FB_SIZE_T i = 0; i < FB_NELEM(conversions); i++) { try { diff --git a/src/common/classes/NoThrowTimeStamp.cpp b/src/common/classes/NoThrowTimeStamp.cpp index 0384cfada24..60a979c93a1 100644 --- a/src/common/classes/NoThrowTimeStamp.cpp +++ b/src/common/classes/NoThrowTimeStamp.cpp @@ -330,7 +330,7 @@ void NoThrowTimeStamp::round_time(ISC_TIME &ntime, const int precision) if (scale <= 0) return; - fb_assert(scale < FB_NELEM(POW_10_TABLE)); + fb_assert(static_cast(scale) < FB_NELEM(POW_10_TABLE)); const ISC_TIME period = POW_10_TABLE[scale]; diff --git a/src/common/pretty.cpp b/src/common/pretty.cpp index b20c0c394a6..d1a0e6956dd 100644 --- a/src/common/pretty.cpp +++ b/src/common/pretty.cpp @@ -159,7 +159,7 @@ int PRETTY_print_cdb(const UCHAR* blr, FPTR_PRINT_CALLBACK routine, void* user_a while (parameter = BLR_BYTE) { const char* p; - if (parameter > FB_NELEM(cdb_table) || !(p = cdb_table[parameter])) + if (parameter > static_cast(FB_NELEM(cdb_table)) || !(p = cdb_table[parameter])) { return error(control, 0, "*** cdb parameter %d is undefined ***\n", parameter); } diff --git a/src/gpre/hsh.cpp b/src/gpre/hsh.cpp index 1d1b4b03607..3afd3d7c451 100644 --- a/src/gpre/hsh.cpp +++ b/src/gpre/hsh.cpp @@ -38,7 +38,7 @@ static int hash(const SCHAR*); static bool scompare(const SCHAR*, const SCHAR*); static bool scompare2(const SCHAR*, const SCHAR*); -const int HASH_SIZE = 211; +const FB_SIZE_T HASH_SIZE = 211; static gpre_sym* hash_table[HASH_SIZE]; static gpre_sym* key_symbols; @@ -80,7 +80,7 @@ void HSH_init() { //const char *string; - int i = 0; + FB_SIZE_T i = 0; for (gpre_sym** ptr = hash_table; i < HASH_SIZE; i++) *ptr++ = NULL; diff --git a/src/include/fb_types.h b/src/include/fb_types.h index 19ee4cf3e69..7c8a43b093c 100644 --- a/src/include/fb_types.h +++ b/src/include/fb_types.h @@ -135,9 +135,9 @@ typedef int (*lock_ast_t)(void*); // Number of elements in an array template -constexpr int FB_NELEM(const T (&)[N]) +constexpr FB_SIZE_T FB_NELEM(const T (&)[N]) { - return N; + return static_cast(N); } // Intl types diff --git a/src/isql/isql.epp b/src/isql/isql.epp index 68563554f2a..8de2929f975 100644 --- a/src/isql/isql.epp +++ b/src/isql/isql.epp @@ -904,7 +904,7 @@ int ISQL_main(int argc, char* argv[]) TEXT helpstring[158]; IUTILS_msg_get(USAGE, sizeof(helpstring), helpstring); STDERROUT(helpstring); - for (int i = 0; i < FB_NELEM(isql_in_sw_table); i++) + for (FB_SIZE_T i = 0; i < FB_NELEM(isql_in_sw_table); i++) { if (isql_in_sw_table[i].in_sw_msg > 0) { @@ -5128,7 +5128,7 @@ static processing_state frontend(const TEXT* statement) // Shift parms to upper case, leaving original case in lparms typedef TEXT* isql_params_t[MAX_TERMS]; isql_params_t parms, lparms; - for (int iter = 0; iter < FB_NELEM(lparms); ++iter) + for (FB_SIZE_T iter = 0; iter < FB_NELEM(lparms); ++iter) { lparms[iter] = NULL; parms[iter] = NULL; diff --git a/src/isql/show.epp b/src/isql/show.epp index c15a22b422a..83903e99a73 100644 --- a/src/isql/show.epp +++ b/src/isql/show.epp @@ -3752,7 +3752,7 @@ static processing_state show_dependencies(const char* object) bool missing = true; - for (int i = 0; i < FB_NELEM(Object_types); ++i) + for (FB_SIZE_T i = 0; i < FB_NELEM(Object_types); ++i) { if (show_dependencies(object, i) == SKIP) { @@ -6709,4 +6709,4 @@ static processing_state show_wireStats() return ps_ERR; return SKIP; -} \ No newline at end of file +} diff --git a/src/jrd/Collation.cpp b/src/jrd/Collation.cpp index a5bc9650f1d..94fde12f1c5 100644 --- a/src/jrd/Collation.cpp +++ b/src/jrd/Collation.cpp @@ -898,7 +898,7 @@ class SleuthMatcher if (*control == *(CharType*) obj->getCanonicalChar(CHAR_GDML_SUBSTITUTE)) { // Note: don't allow substitution characters larger than vector - CharType** const end_vector = vector + (((int) c < FB_NELEM(vector)) ? c : 0); + CharType** const end_vector = vector + ((static_cast(c) < static_cast(FB_NELEM(vector))) ? c : 0); while (v <= end_vector) *v++ = 0; *end_vector = t; diff --git a/src/jrd/SysFunction.cpp b/src/jrd/SysFunction.cpp index 0347d9b8098..4bf7b03a270 100644 --- a/src/jrd/SysFunction.cpp +++ b/src/jrd/SysFunction.cpp @@ -62,6 +62,7 @@ #include "../common/classes/FpeControl.h" #include "../jrd/extds/ExtDS.h" #include "../jrd/align.h" +#include "firebird/impl/types_pub.h" #include #include @@ -2709,7 +2710,7 @@ const char* extractParts[] = const char* getPartName(int n) { - if (n < 0 || n >= FB_NELEM(extractParts) || !extractParts[n]) + if (n < 0 || static_cast(n) >= FB_NELEM(extractParts) || !extractParts[n]) return "Unknown"; return extractParts[n]; diff --git a/src/jrd/blob_filter.cpp b/src/jrd/blob_filter.cpp index 335875aefd6..704574567a9 100644 --- a/src/jrd/blob_filter.cpp +++ b/src/jrd/blob_filter.cpp @@ -239,7 +239,7 @@ BlobFilter* BLF_lookup_internal_filter(thread_db* tdbb, SSHORT from, SSHORT to) // Check for system defined filter - if (to == isc_blob_text && from >= 0 && from < FB_NELEM(filters)) + if (to == isc_blob_text && from >= 0 && static_cast(from) < FB_NELEM(filters)) { BlobFilter* result = FB_NEW_POOL(*dbb->dbb_permanent) BlobFilter(*dbb->dbb_permanent); result->blf_next = NULL; diff --git a/src/jrd/extds/InternalDS.cpp b/src/jrd/extds/InternalDS.cpp index 65585493b60..a576b986a23 100644 --- a/src/jrd/extds/InternalDS.cpp +++ b/src/jrd/extds/InternalDS.cpp @@ -171,7 +171,7 @@ void InternalConnection::attach(thread_db* tdbb) memset(m_features, false, sizeof(m_features)); static const info_features features[] = ENGINE_FEATURES; - for (int i = 0; i < FB_NELEM(features); i++) + for (FB_SIZE_T i = 0; i < FB_NELEM(features); i++) setFeature(features[i]); } diff --git a/src/jrd/filters.cpp b/src/jrd/filters.cpp index c8fec42111d..387b73f0954 100644 --- a/src/jrd/filters.cpp +++ b/src/jrd/filters.cpp @@ -811,7 +811,7 @@ ISC_STATUS filter_transliterate_text(USHORT action, BlobControl* control) { case isc_blob_filter_open: case isc_blob_filter_create: - for (SSHORT i = 0; i < FB_NELEM(control->ctl_data); i++) + for (FB_SIZE_T i = 0; i < FB_NELEM(control->ctl_data); i++) control->ctl_data[i] = 0; aux = NULL; diff --git a/src/jrd/ini.epp b/src/jrd/ini.epp index d0d6527971b..03413fc8d06 100644 --- a/src/jrd/ini.epp +++ b/src/jrd/ini.epp @@ -1619,7 +1619,7 @@ static void store_indices(thread_db* tdbb, USHORT odsVersion) AutoRequest handle1, handle2, handle3; - for (int n = 0; n < SYSTEM_INDEX_COUNT; n++) + for (FB_SIZE_T n = 0; n < SYSTEM_INDEX_COUNT; n++) { const ini_idx_t* index = &indices[n]; const auto relation = MET_relation(tdbb, index->ini_idx_relid); diff --git a/src/jrd/par.cpp b/src/jrd/par.cpp index 97b91112023..3d7442d49d9 100644 --- a/src/jrd/par.cpp +++ b/src/jrd/par.cpp @@ -1519,7 +1519,7 @@ DmlNode* PAR_parse_node(thread_db* tdbb, CompilerScratch* csb) const ULONG blrOffset = csb->csb_blr_reader.getOffset(); const SSHORT blrOperator = csb->csb_blr_reader.getByte(); - if (blrOperator < 0 || blrOperator >= FB_NELEM(blr_parsers)) + if (blrOperator < 0 || static_cast(blrOperator) >= FB_NELEM(blr_parsers)) { // NS: This error string is correct, please do not mangle it again and again. // The whole error message is "BLR syntax error: expected %s at offset %d, encountered %d" diff --git a/src/jrd/sort.cpp b/src/jrd/sort.cpp index 113ee6cbcf0..4a264a4280c 100644 --- a/src/jrd/sort.cpp +++ b/src/jrd/sort.cpp @@ -1525,7 +1525,7 @@ void Sort::mergeRuns(USHORT n) // and there n < RUN_GROUP * MAX_MERGE_LEVEL merge_control blks[RUN_GROUP * MAX_MERGE_LEVEL]; - fb_assert((n - 1) <= FB_NELEM(blks)); // stack var big enough? + fb_assert(static_cast(n - 1) <= FB_NELEM(blks)); // stack var big enough? m_longs -= SIZEOF_SR_BCKPTR_IN_LONGS; diff --git a/src/yvalve/alt.cpp b/src/yvalve/alt.cpp index 2199c7dc11f..4f2e2d2ffbe 100644 --- a/src/yvalve/alt.cpp +++ b/src/yvalve/alt.cpp @@ -250,7 +250,7 @@ ISC_STATUS API_ROUTINE_VARARG gds__start_transaction(ISC_STATUS* status_vector, teb_t tebs[16]; teb_t* teb = tebs; - if (count > FB_NELEM(tebs)) + if (static_cast(count) > FB_NELEM(tebs)) teb = (teb_t*) gds__alloc(((SLONG) sizeof(teb_t) * count)); // FREE: later in this module diff --git a/src/yvalve/gds.cpp b/src/yvalve/gds.cpp index 765b36d5850..a1f13708181 100644 --- a/src/yvalve/gds.cpp +++ b/src/yvalve/gds.cpp @@ -4025,7 +4025,7 @@ static void blr_print_verb(gds_ctl* control, SSHORT level) case blr_invoke_function_type: n = control->ctl_blr_reader.getByte(); - if (n == 0 || n >= FB_NELEM(typeSubCodes)) + if (n == 0 || n >= static_cast(FB_NELEM(typeSubCodes))) blr_error(control, "*** invalid blr_invoke_function_type sub code ***"); blr_format(control, "blr_invoke_function_type_%s,", typeSubCodes[n]); @@ -4123,7 +4123,7 @@ static void blr_print_verb(gds_ctl* control, SSHORT level) case blr_invsel_procedure_type: n = control->ctl_blr_reader.getByte(); - if (n == 0 || n >= FB_NELEM(typeSubCodes)) + if (n == 0 || n >= static_cast(FB_NELEM(typeSubCodes))) blr_error(control, "*** invalid blr_invsel_procedure_type sub code ***"); blr_format(control, "blr_invsel_procedure_type_%s,", typeSubCodes[n]);