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;

src/jrd/SysFunction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "../common/classes/FpeControl.h"
6363
#include "../jrd/extds/ExtDS.h"
6464
#include "../jrd/align.h"
65+
#include "firebird/impl/types_pub.h"
6566

6667
#include <functional>
6768
#include <cmath>
@@ -2709,7 +2710,7 @@ const char* extractParts[] =
27092710

27102711
const char* getPartName(int n)
27112712
{
2712-
if (n < 0 || n >= FB_NELEM(extractParts) || !extractParts[n])
2713+
if (n < 0 || static_cast<FB_SIZE_T>(n) >= FB_NELEM(extractParts) || !extractParts[n])
27132714
return "Unknown";
27142715

27152716
return extractParts[n];

src/jrd/blob_filter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ BlobFilter* BLF_lookup_internal_filter(thread_db* tdbb, SSHORT from, SSHORT to)
239239

240240
// Check for system defined filter
241241

242-
if (to == isc_blob_text && from >= 0 && from < FB_NELEM(filters))
242+
if (to == isc_blob_text && from >= 0 && static_cast<FB_SIZE_T>(from) < FB_NELEM(filters))
243243
{
244244
BlobFilter* result = FB_NEW_POOL(*dbb->dbb_permanent) BlobFilter(*dbb->dbb_permanent);
245245
result->blf_next = NULL;

src/jrd/extds/InternalDS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void InternalConnection::attach(thread_db* tdbb)
171171

172172
memset(m_features, false, sizeof(m_features));
173173
static const info_features features[] = ENGINE_FEATURES;
174-
for (int i = 0; i < FB_NELEM(features); i++)
174+
for (FB_SIZE_T i = 0; i < FB_NELEM(features); i++)
175175
setFeature(features[i]);
176176
}
177177

src/jrd/filters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ ISC_STATUS filter_transliterate_text(USHORT action, BlobControl* control)
811811
{
812812
case isc_blob_filter_open:
813813
case isc_blob_filter_create:
814-
for (SSHORT i = 0; i < FB_NELEM(control->ctl_data); i++)
814+
for (USHORT i = 0; i < FB_NELEM(control->ctl_data); i++)
815815
control->ctl_data[i] = 0;
816816
aux = NULL;
817817

src/jrd/ini.epp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ static void store_indices(thread_db* tdbb, USHORT odsVersion)
16191619

16201620
AutoRequest handle1, handle2, handle3;
16211621

1622-
for (int n = 0; n < SYSTEM_INDEX_COUNT; n++)
1622+
for (FB_SIZE_T n = 0; n < SYSTEM_INDEX_COUNT; n++)
16231623
{
16241624
const ini_idx_t* index = &indices[n];
16251625
const auto relation = MET_relation(tdbb, index->ini_idx_relid);

src/jrd/par.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ DmlNode* PAR_parse_node(thread_db* tdbb, CompilerScratch* csb)
15191519
const ULONG blrOffset = csb->csb_blr_reader.getOffset();
15201520
const SSHORT blrOperator = csb->csb_blr_reader.getByte();
15211521

1522-
if (blrOperator < 0 || blrOperator >= FB_NELEM(blr_parsers))
1522+
if (blrOperator < 0 || static_cast<USHORT>(blrOperator) >= FB_NELEM(blr_parsers))
15231523
{
15241524
// NS: This error string is correct, please do not mangle it again and again.
15251525
// The whole error message is "BLR syntax error: expected %s at offset %d, encountered %d"

src/yvalve/alt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ ISC_STATUS API_ROUTINE_VARARG gds__start_transaction(ISC_STATUS* status_vector,
250250
teb_t tebs[16];
251251
teb_t* teb = tebs;
252252

253-
if (count > FB_NELEM(tebs))
253+
if (static_cast<FB_SIZE_T>(count) > FB_NELEM(tebs))
254254
teb = (teb_t*) gds__alloc(((SLONG) sizeof(teb_t) * count));
255255
// FREE: later in this module
256256

src/yvalve/gds.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4025,7 +4025,7 @@ static void blr_print_verb(gds_ctl* control, SSHORT level)
40254025
case blr_invoke_function_type:
40264026
n = control->ctl_blr_reader.getByte();
40274027

4028-
if (n == 0 || n >= FB_NELEM(typeSubCodes))
4028+
if (n == 0 || n >= static_cast<SSHORT>(FB_NELEM(typeSubCodes)))
40294029
blr_error(control, "*** invalid blr_invoke_function_type sub code ***");
40304030

40314031
blr_format(control, "blr_invoke_function_type_%s,", typeSubCodes[n]);
@@ -4123,7 +4123,7 @@ static void blr_print_verb(gds_ctl* control, SSHORT level)
41234123
case blr_invsel_procedure_type:
41244124
n = control->ctl_blr_reader.getByte();
41254125

4126-
if (n == 0 || n >= FB_NELEM(typeSubCodes))
4126+
if (n == 0 || n >= static_cast<SSHORT>(FB_NELEM(typeSubCodes)))
41274127
blr_error(control, "*** invalid blr_invsel_procedure_type sub code ***");
41284128

41294129
blr_format(control, "blr_invsel_procedure_type_%s,", typeSubCodes[n]);

0 commit comments

Comments
 (0)