Skip to content

Commit 1175a17

Browse files
NoremosArtyom Abakumov
andauthored
Fix windows warnings (C4554, C4018) and mark error message constants as constexpr (C26814) (#8497)
* Fix windows warnings (C4554, C4018) and mark error message constants as constexpr (C26814) * Add FB prefix to STATUS_CONST and undefine it at end --------- Co-authored-by: Artyom Abakumov <[email protected]>
1 parent 90fd992 commit 1175a17

File tree

13 files changed

+49
-41
lines changed

13 files changed

+49
-41
lines changed

src/burp/BurpTasks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ void RestoreRelationTask::verbRecs(FB_UINT64& records, bool total)
840840

841841
void RestoreRelationTask::verbRecsFinal()
842842
{
843-
if (m_verbRecs < m_records)
843+
if (m_verbRecs < static_cast<FB_UINT64>(m_records))
844844
{
845845
m_verbRecs = m_records;
846846
BURP_verbose(107, SafeArg() << m_verbRecs);

src/burp/restore.epp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12406,7 +12406,7 @@ bool RestoreRelationTask::fileReader(Item& item)
1240612406
const FB_SSIZE_T attLen = 1 + (tdgbl->gbl_sw_transportable ? 12 : 6);
1240712407
const FB_SSIZE_T overhead = tdgbl->gbl_sw_compress ? (len / 127 + 1) : 0;
1240812408

12409-
if (len + attLen + overhead > space)
12409+
if (static_cast<FB_SSIZE_T>(len) + attLen + overhead > space)
1241012410
{
1241112411
if (ioBuf)
1241212412
{

src/common/unicode_util.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ UnicodeUtil::Utf16Collation* UnicodeUtil::Utf16Collation::create(
16151615

16161616
if (len >= 2)
16171617
{
1618-
obj->maxContractionsPrefixLength = len - 1 > obj->maxContractionsPrefixLength ?
1618+
obj->maxContractionsPrefixLength = static_cast<ULONG>(len - 1) > obj->maxContractionsPrefixLength ?
16191619
len - 1 : obj->maxContractionsPrefixLength;
16201620

16211621
UCHAR key[100];
@@ -1865,7 +1865,7 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src
18651865
lastCharKeyLen = icu->ucolGetSortKey(coll,
18661866
reinterpret_cast<const UChar*>(src + srcLenLong), i, lastCharKey, sizeof(lastCharKey));
18671867

1868-
if (prefixLen == 0 || prefixLen > dstLen - 2 || prefixLen > MAX_USHORT ||
1868+
if (prefixLen == 0 || prefixLen > dstLen - 2u || prefixLen > MAX_USHORT ||
18691869
lastCharKeyLen == 0)
18701870
{
18711871
return INTL_BAD_KEY_LENGTH;
@@ -1895,7 +1895,7 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src
18951895

18961896
const ULONG keyLen = prefixLen + keyIt.getCount() - advance;
18971897

1898-
if (keyLen > dstLen - 2 || keyLen > MAX_USHORT)
1898+
if (keyLen > dstLen - 2u || keyLen > MAX_USHORT)
18991899
return INTL_BAD_KEY_LENGTH;
19001900

19011901
dst[0] = UCHAR(keyLen & 0xFF);
@@ -1920,7 +1920,7 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src
19201920
ULONG keyLen = icu->ucolGetSortKey(coll,
19211921
reinterpret_cast<const UChar*>(src), srcLenLong, originalDst + 2, originalDstLen - 3);
19221922

1923-
if (keyLen == 0 || keyLen > originalDstLen - 3 || keyLen > MAX_USHORT)
1923+
if (keyLen == 0 || keyLen > originalDstLen - 3u || keyLen > MAX_USHORT)
19241924
return INTL_BAD_KEY_LENGTH;
19251925

19261926
fb_assert(originalDst[2 + keyLen - 1] == '\0');

src/dsql/BoolNodes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ bool ComparativeBoolNode::stringBoolean(thread_db* tdbb, Request* request, dsc*
10581058
cache->matcher->reset();
10591059
else
10601060
{
1061-
if (cache && cache->keySize < patternLen + escapeLen)
1061+
if (cache && cache->keySize < static_cast<ULONG>(patternLen) + escapeLen)
10621062
{
10631063
delete cache;
10641064
cache = nullptr;

src/dsql/ExprNodes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12194,11 +12194,11 @@ dsc* SubstringSimilarNode::execute(thread_db* tdbb, Request* request) const
1219412194

1219512195
MoveBuffer patternBuffer;
1219612196
UCHAR* patternStr;
12197-
int patternLen = MOV_make_string2(tdbb, patternDesc, textType, &patternStr, patternBuffer);
12197+
ULONG patternLen = MOV_make_string2(tdbb, patternDesc, textType, &patternStr, patternBuffer);
1219812198

1219912199
MoveBuffer escapeBuffer;
1220012200
UCHAR* escapeStr;
12201-
int escapeLen = MOV_make_string2(tdbb, escapeDesc, textType, &escapeStr, escapeBuffer);
12201+
ULONG escapeLen = MOV_make_string2(tdbb, escapeDesc, textType, &escapeStr, escapeBuffer);
1220212202

1220312203
// Verify the correctness of the escape character.
1220412204
if (escapeLen == 0 || charSet->length(escapeLen, escapeStr, true) != 1)

src/dsql/StmtNodes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,7 +3428,7 @@ ExecProcedureNode* ExecProcedureNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
34283428
const auto positionalArgCount = inputSources->items.getCount() -
34293429
(dsqlInputArgNames ? dsqlInputArgNames->getCount() : 0);
34303430

3431-
if (positionalArgCount > procedure->prc_in_count || dsqlInputArgNames)
3431+
if (static_cast<SSHORT>(positionalArgCount) > procedure->prc_in_count || dsqlInputArgNames)
34323432
{
34333433
const auto newInputs = FB_NEW_POOL(pool) ValueListNode(pool);
34343434
const auto newOutputs = FB_NEW_POOL(pool) ValueListNode(pool);
@@ -3443,7 +3443,7 @@ ExecProcedureNode* ExecProcedureNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
34433443

34443444
for (auto source : inputSources->items)
34453445
{
3446-
const bool isInput = (pos < positionalArgCount && pos < procedure->prc_in_count) ||
3446+
const bool isInput = (pos < positionalArgCount && pos < static_cast<unsigned>(procedure->prc_in_count)) ||
34473447
(pos >= positionalArgCount &&
34483448
!outFields.exist((*dsqlInputArgNames)[pos - positionalArgCount]));
34493449

src/include/firebird/iberror.h

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,38 @@
1717

1818
#ifdef __cplusplus /* c++ definitions */
1919

20-
const ISC_STATUS isc_facility = 20;
21-
const ISC_STATUS isc_base = isc_facility << 24;
22-
const ISC_STATUS isc_factor = 1;
23-
24-
const ISC_STATUS isc_arg_end = 0; // end of argument list
25-
const ISC_STATUS isc_arg_gds = 1; // generic DSRI status value
26-
const ISC_STATUS isc_arg_string = 2; // string argument
27-
const ISC_STATUS isc_arg_cstring = 3; // count & string argument
28-
const ISC_STATUS isc_arg_number = 4; // numeric argument (long)
29-
const ISC_STATUS isc_arg_interpreted = 5; // interpreted status code (string)
30-
const ISC_STATUS isc_arg_vms = 6; // VAX/VMS status code (long)
31-
const ISC_STATUS isc_arg_unix = 7; // UNIX error code
32-
const ISC_STATUS isc_arg_domain = 8; // Apollo/Domain error code
33-
const ISC_STATUS isc_arg_dos = 9; // MSDOS/OS2 error code
34-
const ISC_STATUS isc_arg_mpexl = 10; // HP MPE/XL error code
35-
const ISC_STATUS isc_arg_mpexl_ipc = 11; // HP MPE/XL IPC error code
36-
const ISC_STATUS isc_arg_next_mach = 15; // NeXT/Mach error code
37-
const ISC_STATUS isc_arg_netware = 16; // NetWare error code
38-
const ISC_STATUS isc_arg_win32 = 17; // Win32 error code
39-
const ISC_STATUS isc_arg_warning = 18; // warning argument
40-
const ISC_STATUS isc_arg_sql_state = 19; // SQLSTATE
20+
#if __cplusplus >= 201703L // C++17 or later
21+
#define FB_STATUS_CONST inline constexpr ISC_STATUS
22+
#else
23+
#define FB_STATUS_CONST const ISC_STATUS
24+
#endif
25+
26+
FB_STATUS_CONST isc_facility = 20;
27+
FB_STATUS_CONST isc_base = isc_facility << 24;
28+
FB_STATUS_CONST isc_factor = 1;
29+
30+
FB_STATUS_CONST isc_arg_end = 0; // end of argument list
31+
FB_STATUS_CONST isc_arg_gds = 1; // generic DSRI status value
32+
FB_STATUS_CONST isc_arg_string = 2; // string argument
33+
FB_STATUS_CONST isc_arg_cstring = 3; // count & string argument
34+
FB_STATUS_CONST isc_arg_number = 4; // numeric argument (long)
35+
FB_STATUS_CONST isc_arg_interpreted = 5; // interpreted status code (string)
36+
FB_STATUS_CONST isc_arg_vms = 6; // VAX/VMS status code (long)
37+
FB_STATUS_CONST isc_arg_unix = 7; // UNIX error code
38+
FB_STATUS_CONST isc_arg_domain = 8; // Apollo/Domain error code
39+
FB_STATUS_CONST isc_arg_dos = 9; // MSDOS/OS2 error code
40+
FB_STATUS_CONST isc_arg_mpexl = 10; // HP MPE/XL error code
41+
FB_STATUS_CONST isc_arg_mpexl_ipc = 11; // HP MPE/XL IPC error code
42+
FB_STATUS_CONST isc_arg_next_mach = 15; // NeXT/Mach error code
43+
FB_STATUS_CONST isc_arg_netware = 16; // NetWare error code
44+
FB_STATUS_CONST isc_arg_win32 = 17; // Win32 error code
45+
FB_STATUS_CONST isc_arg_warning = 18; // warning argument
46+
FB_STATUS_CONST isc_arg_sql_state = 19; // SQLSTATE
4147

4248
#define FB_IMPL_MSG_NO_SYMBOL(facility, number, text)
4349

4450
#define FB_IMPL_MSG_SYMBOL(facility, number, symbol, text) \
45-
const ISC_STATUS isc_##symbol = FB_IMPL_MSG_ENCODE(number, FB_IMPL_MSG_FACILITY_##facility);
51+
FB_STATUS_CONST isc_##symbol = FB_IMPL_MSG_ENCODE(number, FB_IMPL_MSG_FACILITY_##facility);
4652

4753
#define FB_IMPL_MSG(facility, number, symbol, sqlCode, sqlClass, sqlSubClass, text) \
4854
FB_IMPL_MSG_SYMBOL(facility, number, symbol, text)
@@ -53,7 +59,7 @@ const ISC_STATUS isc_arg_sql_state = 19; // SQLSTATE
5359
#undef FB_IMPL_MSG_SYMBOL
5460
#undef FB_IMPL_MSG
5561

56-
const ISC_STATUS isc_err_max = 0
62+
FB_STATUS_CONST isc_err_max = 0
5763
#define FB_IMPL_MSG_NO_SYMBOL(facility, number, text)
5864
#define FB_IMPL_MSG_SYMBOL(facility, number, symbol, text)
5965
#define FB_IMPL_MSG(facility, number, symbol, sqlCode, sqlClass, sqlSubClass, text) + 1
@@ -66,6 +72,8 @@ const ISC_STATUS isc_err_max = 0
6672
;
6773

6874

75+
#undef FB_STATUS_CONST
76+
6977
#else /* c definitions */
7078

7179
#define isc_facility 20

src/isql/isql.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const int ISQL_MSG_FAC = FB_IMPL_MSG_FACILITY_ISQL;
111111
#define FB_IMPL_MSG_NO_SYMBOL(facility, number, text)
112112

113113
#define FB_IMPL_MSG_SYMBOL(facility, number, symbol, text) \
114-
const int symbol = number;
114+
inline constexpr int symbol = number;
115115

116116
#define FB_IMPL_MSG(facility, number, symbol, sqlCode, sqlClass, sqlSubClass, text) \
117117
FB_IMPL_MSG_SYMBOL(facility, number, symbol, text)

src/jrd/ExtEngineManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ namespace
318318
checkMessageEof(aCheckMessageEof)
319319
{
320320
// Iterate over the format items, except the EOF item.
321-
for (unsigned i = 0; i < (fromMessage->format->fmt_count / 2) * 2; i += 2)
321+
for (unsigned i = 0; i < (fromMessage->format->fmt_count / 2u) * 2u; i += 2)
322322
{
323323
auto flag = FB_NEW_POOL(pool) ParameterNode(pool);
324324
flag->messageNumber = fromMessage->messageNumber;

src/jrd/idx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ bool IndexCreateTask::getResult(IStatus* status)
808808

809809
int IndexCreateTask::getMaxWorkers()
810810
{
811-
const int parWorkers = m_items.getCount();
811+
const FB_SIZE_T parWorkers = m_items.getCount();
812812
if (parWorkers == 1 || m_countPP == 0)
813813
return 1;
814814

0 commit comments

Comments
 (0)