Skip to content

Commit f30c24f

Browse files
committed
Fix conversion warnings in DecFloat
+ constexpr
1 parent 271cb2a commit f30c24f

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

src/common/DecFloat.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct Dec2fb
6161
ISC_STATUS fbDoubleError;
6262
};
6363

64-
Dec2fb dec2fb[] = {
64+
constexpr Dec2fb dec2fb[] = {
6565
{ DEC_IEEE_754_Division_by_zero, isc_decfloat_divide_by_zero, isc_exception_float_divide_by_zero },
6666
{ DEC_IEEE_754_Inexact, isc_decfloat_inexact_result, isc_exception_float_inexact_result },
6767
{ DEC_IEEE_754_Invalid_operation, isc_decfloat_invalid_operation, isc_exception_float_invalid_operand },
@@ -103,7 +103,7 @@ class DecimalContext : public decContext
103103

104104
decContextZeroStatus(this);
105105

106-
for (Dec2fb* e = dec2fb; e->decError; ++e)
106+
for (const Dec2fb* e = dec2fb; e->decError; ++e)
107107
{
108108
// Arg::Gds(isc_arith_except) as first vector element ?
109109
if (e->decError & unmaskedExceptions)
@@ -162,9 +162,9 @@ unsigned digits(const unsigned pMax, unsigned char* const coeff, int& exp)
162162
}
163163

164164
// offsets down from MAX_SLONG
165-
const ULONG OFF_inf = 3;
166-
const ULONG OFF_snan = 2;
167-
const ULONG OFF_nan = 1;
165+
constexpr ULONG OFF_inf = 3;
166+
constexpr ULONG OFF_snan = 2;
167+
constexpr ULONG OFF_nan = 1;
168168

169169
void make(ULONG* key,
170170
const unsigned pMax, const int bias, const unsigned decSize,
@@ -426,10 +426,11 @@ void Decimal64::toString(DecimalStatus decSt, unsigned length, char* to) const
426426
memset(s, 0, sizeof(s));
427427
decDoubleToString(&dec, s);
428428

429-
if (strlen(s) > length)
429+
const FB_SIZE_T sLen = fb_strlen(s);
430+
if (sLen > length)
430431
decContextSetStatus(&context, DEC_Invalid_operation);
431432
else
432-
length = strlen(s);
433+
length = sLen;
433434

434435
memcpy(to, s, length + 1);
435436
}
@@ -718,10 +719,11 @@ void Decimal128::toString(DecimalStatus decSt, unsigned length, char* to) const
718719
memset(s, 0, sizeof(s));
719720
decQuadToString(&dec, s);
720721

721-
if (strlen(s) > length)
722+
const FB_SIZE_T sLen = fb_strlen(s);
723+
if (sLen > length)
722724
decContextSetStatus(&context, DEC_Invalid_operation);
723725
else
724-
length = strlen(s);
726+
length = sLen;
725727

726728
memcpy(to, s, length + 1);
727729
}

src/common/DecFloat.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct DecFloatConstant
6666
//#define FB_DECLOAT_CONST(x) { STRINGIZE(x), x }
6767
#define FB_DECLOAT_CONST(x) { #x, x }
6868

69-
const DecFloatConstant FB_DEC_RoundModes[] = {
69+
inline constexpr DecFloatConstant FB_DEC_RoundModes[] = {
7070
FB_DECLOAT_CONST(DEC_ROUND_CEILING),
7171
FB_DECLOAT_CONST(DEC_ROUND_UP),
7272
FB_DECLOAT_CONST(DEC_ROUND_HALF_UP),
@@ -80,9 +80,9 @@ const DecFloatConstant FB_DEC_RoundModes[] = {
8080

8181
//DEC_ROUND_
8282
//0123456789
83-
const unsigned FB_DEC_RMODE_OFFSET = 10;
83+
inline constexpr unsigned FB_DEC_RMODE_OFFSET = 10;
8484

85-
const DecFloatConstant FB_DEC_IeeeTraps[] = {
85+
inline constexpr DecFloatConstant FB_DEC_IeeeTraps[] = {
8686
FB_DECLOAT_CONST(DEC_IEEE_754_Division_by_zero),
8787
FB_DECLOAT_CONST(DEC_IEEE_754_Inexact),
8888
FB_DECLOAT_CONST(DEC_IEEE_754_Invalid_operation),
@@ -93,18 +93,18 @@ const DecFloatConstant FB_DEC_IeeeTraps[] = {
9393

9494
//DEC_IEEE_754_
9595
//0123456789012
96-
const unsigned FB_DEC_TRAPS_OFFSET = 13;
96+
inline constexpr unsigned FB_DEC_TRAPS_OFFSET = 13;
9797

9898
#undef FB_DECLOAT_CONST
9999

100-
static const USHORT FB_DEC_Errors =
100+
static inline constexpr USHORT FB_DEC_Errors =
101101
DEC_IEEE_754_Division_by_zero |
102102
DEC_IEEE_754_Invalid_operation |
103103
DEC_IEEE_754_Overflow;
104104

105105
struct DecimalStatus
106106
{
107-
DecimalStatus(USHORT exc)
107+
DecimalStatus(USHORT exc) noexcept
108108
: decExtFlag(exc),
109109
roundingMode(DEC_ROUND_HALF_UP)
110110
{}
@@ -127,18 +127,18 @@ struct NumericBinding
127127
NUM_INT64
128128
};
129129

130-
NumericBinding()
130+
NumericBinding() noexcept
131131
: bind(NUM_NATIVE),
132132
numScale(0)
133133
{}
134134

135-
NumericBinding(Bind aBind, SCHAR aNumScale = 0)
135+
NumericBinding(Bind aBind, SCHAR aNumScale = 0) noexcept
136136
: bind(aBind),
137137
numScale(aNumScale)
138138
{}
139139

140140
static const NumericBinding DEFAULT;
141-
static const SCHAR MAX_SCALE = 18;
141+
static inline constexpr SCHAR MAX_SCALE = 18;
142142

143143
Bind bind;
144144
SCHAR numScale;
@@ -175,7 +175,7 @@ class Decimal64
175175
bool isNan() const;
176176
int sign() const;
177177

178-
static ULONG getKeyLength()
178+
static constexpr ULONG getKeyLength() noexcept
179179
{
180180
return sizeof(Decimal64) + sizeof(ULONG);
181181
}
@@ -251,15 +251,15 @@ class Decimal128
251251
bool isNan() const;
252252
int sign() const;
253253

254-
static ULONG getKeyLength()
254+
static constexpr ULONG getKeyLength() noexcept
255255
{
256256
return sizeof(Decimal128) + sizeof(ULONG);
257257
}
258258

259259
void makeKey(ULONG* key) const;
260260
void grabKey(ULONG* key);
261261

262-
static ULONG getIndexKeyLength()
262+
static constexpr ULONG getIndexKeyLength() noexcept
263263
{
264264
return 17;
265265
}
@@ -313,8 +313,8 @@ class CDecimal128 : public Decimal128
313313
static_assert(sizeof(Decimal64) % sizeof(ULONG) == 0, "Decimal64 size mismatch");
314314
static_assert(sizeof(Decimal128) % sizeof(ULONG) == 0, "Decimal128 size mismatch");
315315

316-
static const size_t MAX_DEC_LONGS = MAX(sizeof(Decimal64), sizeof(Decimal128)) >> SHIFTLONG;
317-
static const size_t MAX_DEC_KEY_LONGS = MAX_DEC_LONGS + 1; // key is one longword bigger
316+
static inline constexpr size_t MAX_DEC_LONGS = MAX(sizeof(Decimal64), sizeof(Decimal128)) >> SHIFTLONG;
317+
static inline constexpr size_t MAX_DEC_KEY_LONGS = MAX_DEC_LONGS + 1; // key is one longword bigger
318318

319319
} // namespace Firebird
320320

0 commit comments

Comments
 (0)