Skip to content

Commit 0ae47e1

Browse files
author
Artyom Abakumov
committed
Change FB_NELEM return type to unsigned and resolve all FB_NELEM related Wsign-compare warnings
1 parent 30b77dd commit 0ae47e1

File tree

18 files changed

+26
-25
lines changed

18 files changed

+26
-25
lines changed

src/common/CvtFormat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ namespace
13311331
bool isFound = false;
13321332

13331333
std::string_view monthShortName = getSubstringFromString(str, strLength, strOffset, 3);
1334-
for (int i = 0; i < FB_NELEM(FB_SHORT_MONTHS) - 1; i++)
1334+
for (FB_SIZE_T i = 0; i < FB_NELEM(FB_SHORT_MONTHS) - 1; i++)
13351335
{
13361336
if (std::equal(monthShortName.begin(), monthShortName.end(),
13371337
FB_SHORT_MONTHS[i], FB_SHORT_MONTHS[i] + strlen(FB_SHORT_MONTHS[i]),
@@ -1352,7 +1352,7 @@ namespace
13521352
bool isFound = false;
13531353

13541354
std::string_view monthFullName = getSubstringFromString(str, strLength, strOffset);
1355-
for (int i = 0; i < FB_NELEM(FB_LONG_MONTHS_UPPER) - 1; i++)
1355+
for (FB_SIZE_T i = 0; i < FB_NELEM(FB_LONG_MONTHS_UPPER) - 1; i++)
13561356
{
13571357
if (std::equal(monthFullName.begin(), monthFullName.end(),
13581358
FB_LONG_MONTHS_UPPER[i], FB_LONG_MONTHS_UPPER[i] + strlen(FB_LONG_MONTHS_UPPER[i]),

src/common/SimilarToRegex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ namespace
410410
if (!hasPatternChar() || getPatternChar() != ']')
411411
status_exception::raise(Arg::Gds(isc_invalid_similar_pattern));
412412

413-
for (item.clazz = 0; item.clazz < FB_NELEM(classes); ++item.clazz)
413+
for (item.clazz = 0; static_cast<FB_SIZE_T>(item.clazz) < FB_NELEM(classes); ++item.clazz)
414414
{
415415
if (fb_utils::strnicmp(patternStr + charSavePos,
416416
classes[item.clazz].similarClass, len) == 0)
@@ -419,7 +419,7 @@ namespace
419419
}
420420
}
421421

422-
if (item.clazz >= FB_NELEM(classes))
422+
if (static_cast<FB_SIZE_T>(item.clazz) >= FB_NELEM(classes))
423423
status_exception::raise(Arg::Gds(isc_invalid_similar_pattern));
424424
}
425425
else

src/common/TextType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ TextType::TextType(TTYPE_ID _type, texttype *_tt, USHORT _attributes, CharSet* _
153153
{'S', CHAR_UPPER_S}
154154
};
155155

156-
for (int i = 0; i < FB_NELEM(conversions); i++)
156+
for (FB_SIZE_T i = 0; i < FB_NELEM(conversions); i++)
157157
{
158158
try
159159
{

src/common/classes/NoThrowTimeStamp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void NoThrowTimeStamp::round_time(ISC_TIME &ntime, const int precision)
330330
if (scale <= 0)
331331
return;
332332

333-
fb_assert(scale < FB_NELEM(POW_10_TABLE));
333+
fb_assert(static_cast<FB_SIZE_T>(scale) < FB_NELEM(POW_10_TABLE));
334334

335335
const ISC_TIME period = POW_10_TABLE[scale];
336336

src/common/pretty.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int PRETTY_print_cdb(const UCHAR* blr, FPTR_PRINT_CALLBACK routine, void* user_a
159159
while (parameter = BLR_BYTE)
160160
{
161161
const char* p;
162-
if (parameter > FB_NELEM(cdb_table) || !(p = cdb_table[parameter]))
162+
if (parameter > static_cast<SSHORT>(FB_NELEM(cdb_table)) || !(p = cdb_table[parameter]))
163163
{
164164
return error(control, 0, "*** cdb parameter %d is undefined ***\n", parameter);
165165
}

src/gpre/hsh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int hash(const SCHAR*);
3838
static bool scompare(const SCHAR*, const SCHAR*);
3939
static bool scompare2(const SCHAR*, const SCHAR*);
4040

41-
const int HASH_SIZE = 211;
41+
const FB_SIZE_T HASH_SIZE = 211;
4242

4343
static gpre_sym* hash_table[HASH_SIZE];
4444
static gpre_sym* key_symbols;
@@ -80,7 +80,7 @@ void HSH_init()
8080
{
8181
//const char *string;
8282

83-
int i = 0;
83+
FB_SIZE_T i = 0;
8484
for (gpre_sym** ptr = hash_table; i < HASH_SIZE; i++)
8585
*ptr++ = NULL;
8686

src/include/fb_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ typedef int (*lock_ast_t)(void*);
135135

136136
// Number of elements in an array
137137
template <typename T, std::size_t N>
138-
constexpr int FB_NELEM(const T (&)[N])
138+
constexpr FB_SIZE_T FB_NELEM(const T (&)[N])
139139
{
140-
return N;
140+
return static_cast<FB_SIZE_T>(N);
141141
}
142142

143143
// Intl types

src/isql/isql.epp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ int ISQL_main(int argc, char* argv[])
904904
TEXT helpstring[158];
905905
IUTILS_msg_get(USAGE, sizeof(helpstring), helpstring);
906906
STDERROUT(helpstring);
907-
for (int i = 0; i < FB_NELEM(isql_in_sw_table); i++)
907+
for (FB_SIZE_T i = 0; i < FB_NELEM(isql_in_sw_table); i++)
908908
{
909909
if (isql_in_sw_table[i].in_sw_msg > 0)
910910
{
@@ -5128,7 +5128,7 @@ static processing_state frontend(const TEXT* statement)
51285128
// Shift parms to upper case, leaving original case in lparms
51295129
typedef TEXT* isql_params_t[MAX_TERMS];
51305130
isql_params_t parms, lparms;
5131-
for (int iter = 0; iter < FB_NELEM(lparms); ++iter)
5131+
for (FB_SIZE_T iter = 0; iter < FB_NELEM(lparms); ++iter)
51325132
{
51335133
lparms[iter] = NULL;
51345134
parms[iter] = NULL;

src/isql/show.epp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,7 +3752,7 @@ static processing_state show_dependencies(const char* object)
37523752

37533753
bool missing = true;
37543754

3755-
for (int i = 0; i < FB_NELEM(Object_types); ++i)
3755+
for (FB_SIZE_T i = 0; i < FB_NELEM(Object_types); ++i)
37563756
{
37573757
if (show_dependencies(object, i) == SKIP)
37583758
{
@@ -6709,4 +6709,4 @@ static processing_state show_wireStats()
67096709
return ps_ERR;
67106710

67116711
return SKIP;
6712-
}
6712+
}

src/jrd/Collation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ class SleuthMatcher
898898
if (*control == *(CharType*) obj->getCanonicalChar(CHAR_GDML_SUBSTITUTE))
899899
{
900900
// Note: don't allow substitution characters larger than vector
901-
CharType** const end_vector = vector + (((int) c < FB_NELEM(vector)) ? c : 0);
901+
CharType** const end_vector = vector + ((static_cast<FB_SSIZE_T>(c) < static_cast<FB_SSIZE_T>(FB_NELEM(vector))) ? c : 0);
902902
while (v <= end_vector)
903903
*v++ = 0;
904904
*end_vector = t;

0 commit comments

Comments
 (0)