Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change FB_NELEM return type to unsigned and resolve all FB_NELEM related Wsign-compare warnings #8338

Merged
merged 3 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common/CvtFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand All @@ -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]),
Expand Down
4 changes: 2 additions & 2 deletions src/common/SimilarToRegex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FB_SIZE_T>(item.clazz) < FB_NELEM(classes); ++item.clazz)
{
if (fb_utils::strnicmp(patternStr + charSavePos,
classes[item.clazz].similarClass, len) == 0)
Expand All @@ -419,7 +419,7 @@ namespace
}
}

if (item.clazz >= FB_NELEM(classes))
if (static_cast<FB_SIZE_T>(item.clazz) >= FB_NELEM(classes))
status_exception::raise(Arg::Gds(isc_invalid_similar_pattern));
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/common/TextType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/classes/NoThrowTimeStamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FB_SIZE_T>(scale) < FB_NELEM(POW_10_TABLE));

const ISC_TIME period = POW_10_TABLE[scale];

Expand Down
2 changes: 1 addition & 1 deletion src/common/pretty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SSHORT>(FB_NELEM(cdb_table)) || !(p = cdb_table[parameter]))
{
return error(control, 0, "*** cdb parameter %d is undefined ***\n", parameter);
}
Expand Down
4 changes: 2 additions & 2 deletions src/gpre/hsh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/include/fb_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ typedef int (*lock_ast_t)(void*);

// Number of elements in an array
template <typename T, std::size_t N>
constexpr int FB_NELEM(const T (&)[N])
constexpr FB_SIZE_T FB_NELEM(const T (&)[N])
{
return N;
return static_cast<FB_SIZE_T>(N);
}

// Intl types
Expand Down
4 changes: 2 additions & 2 deletions src/isql/isql.epp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/isql/show.epp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -6709,4 +6709,4 @@ static processing_state show_wireStats()
return ps_ERR;

return SKIP;
}
}
2 changes: 1 addition & 1 deletion src/jrd/Collation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FB_SSIZE_T>(c) < static_cast<FB_SSIZE_T>(FB_NELEM(vector))) ? c : 0);
while (v <= end_vector)
*v++ = 0;
*end_vector = t;
Expand Down
3 changes: 2 additions & 1 deletion src/jrd/SysFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <functional>
#include <cmath>
Expand Down Expand Up @@ -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<FB_SIZE_T>(n) >= FB_NELEM(extractParts) || !extractParts[n])
return "Unknown";

return extractParts[n];
Expand Down
2 changes: 1 addition & 1 deletion src/jrd/blob_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FB_SIZE_T>(from) < FB_NELEM(filters))
{
BlobFilter* result = FB_NEW_POOL(*dbb->dbb_permanent) BlobFilter(*dbb->dbb_permanent);
result->blf_next = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/jrd/extds/InternalDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/jrd/filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (USHORT i = 0; i < FB_NELEM(control->ctl_data); i++)
Noremos marked this conversation as resolved.
Show resolved Hide resolved
control->ctl_data[i] = 0;
aux = NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/jrd/ini.epp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/jrd/par.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<USHORT>(blrOperator) >= FB_NELEM(blr_parsers))
Noremos marked this conversation as resolved.
Show resolved Hide resolved
{
// 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"
Expand Down
2 changes: 1 addition & 1 deletion src/yvalve/alt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FB_SIZE_T>(count) > FB_NELEM(tebs))
teb = (teb_t*) gds__alloc(((SLONG) sizeof(teb_t) * count));
// FREE: later in this module

Expand Down
4 changes: 2 additions & 2 deletions src/yvalve/gds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SSHORT>(FB_NELEM(typeSubCodes)))
Noremos marked this conversation as resolved.
Show resolved Hide resolved
blr_error(control, "*** invalid blr_invoke_function_type sub code ***");

blr_format(control, "blr_invoke_function_type_%s,", typeSubCodes[n]);
Expand Down Expand Up @@ -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<SSHORT>(FB_NELEM(typeSubCodes)))
Noremos marked this conversation as resolved.
Show resolved Hide resolved
blr_error(control, "*** invalid blr_invsel_procedure_type sub code ***");

blr_format(control, "blr_invsel_procedure_type_%s,", typeSubCodes[n]);
Expand Down
Loading