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

The part of fix #7599. Problems with pointers in decNumber library (#7607)
All checks were successful
continuous-integration/drone/push Build is passing

* Fix for #7599 - strip leading zeros in decFloatFromString
* Bug fix for #7599 - the scope of a local buffer in decFinalize was corrected
This commit is contained in:
Dmitry Kovalenko 2023-05-30 13:25:22 +03:00 committed by GitHub
parent 2d769bb96a
commit f5af6a92c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -236,6 +236,7 @@ static decFloat * decFinalize(decFloat *df, bcdnum *num,
uByte *ulsd=num->lsd; // ..
uInt encode; // encoding accumulator
Int length; // coefficient length
uByte buffer[ROUNDUP(DECPMAX+3, 4)]; // [+3 allows uInt padding]
#if DECCHECK
Int clen=ulsd-umsd+1;
@ -456,7 +457,6 @@ static decFloat * decFinalize(decFloat *df, bcdnum *num,
// fold down needed; must copy to buffer in order to pad
// with zeros safely; fortunately this is not the worst case
// path because cannot have had a round
uByte buffer[ROUNDUP(DECPMAX+3, 4)]; // [+3 allows uInt padding]
uByte *s=umsd; // source
uByte *t=buffer; // safe target
uByte *tlsd=buffer+(ulsd-umsd)+shift; // target LSD
@ -905,16 +905,20 @@ decFloat * decFloatFromString(decFloat *result, const char *string,
else { // too long for buffer
// [This is a rare and unusual case; arbitrary-length input]
// strip leading zeros [but leave final 0 if all 0's]
if (*cfirst=='.') cfirst++; // step past dot at start
if (*cfirst=='0') { // [cfirst always -> digit]
for (; cfirst<clast; cfirst++) {
if (*cfirst!='0') { // non-zero found
if (*cfirst=='.') continue; // [ignore]
break; // done
}
digits--; // 0 stripped
{
const char* cfirst2=NULL;
for (; cfirst<=clast; cfirst++) {
if (*cfirst == '.') continue; // [ignore]
cfirst2=cfirst; // let's save the position of this digit
if (*cfirst!='0') break; // done
digits--; // 0 stripped
} // cfirst
} // at least one leading 0
if(clast<cfirst) { // all the symbols are ZEROs
digits=1;
}
cfirst=cfirst2;
} // local - at least one leading 0
// the coefficient is now as short as possible, but may still
// be too long; copy up to Pmax+1 digits to the buffer, then