8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 22:43:03 +01:00

Fixed AV and other issues found by FBT test bugs.core_6353.

Alex, please review.
This commit is contained in:
Vlad Khorsun 2022-07-05 10:53:16 +03:00
parent 6285e8c459
commit 859b895b07
2 changed files with 29 additions and 11 deletions

View File

@ -659,16 +659,34 @@ ULONG Int128::makeIndexKey(vary* buf, int exp)
unsigned char coeff[PMAX + 2];
unsigned char* c = &coeff[PMAX];
for (Int128 v = abs(); v.sign(); )
{
unsigned int m;
v.divMod(10, &m);
fb_assert(m < 10);
fb_assert(c >= coeff);
*--c = m;
if (sign() > 0)
{
for (Int128 v = *this; v.sign(); )
{
int m;
v.divMod(10, &m);
fb_assert(m < 10);
fb_assert(c > coeff);
*--c = m;
}
}
memset(coeff, 0, c - coeff);
else
{
for (Int128 v = *this; v.sign(); )
{
int m;
v.divMod(10, &m);
fb_assert(-m < 10);
fb_assert(c > coeff);
*--c = -m;
}
}
if (c > coeff)
memset(coeff, 0, c - coeff);
return Decimal128::makeBcdKey(buf, coeff, sign() < 0, exp, BIAS, PMAX);
}

View File

@ -285,7 +285,7 @@ public:
return rc;
}
void divMod(unsigned int divisor, unsigned int* remainder)
void divMod(int divisor, int* remainder)
{
absl::int128 d = divisor;
*remainder = int(v % d);
@ -549,7 +549,7 @@ public:
return rc;
}
void divMod(unsigned int divisor, unsigned int* remainder)
void divMod(int divisor, int* remainder)
{
ttmath::sint rem;
v.DivInt(divisor, &rem);
@ -566,7 +566,7 @@ public:
}
static const unsigned BIAS = 128;
static const unsigned PMAX = 38;
static const unsigned PMAX = 39;
ULONG makeIndexKey(vary* buf, int scale);