mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 16:03: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
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
(cherry picked from commit f5af6a92c6
)
This commit is contained in:
parent
30b7852c76
commit
a31b3bcb5b
24
extern/decNumber/decCommon.c
vendored
24
extern/decNumber/decCommon.c
vendored
@ -236,6 +236,7 @@ static decFloat * decFinalize(decFloat *df, bcdnum *num,
|
|||||||
uByte *ulsd=num->lsd; // ..
|
uByte *ulsd=num->lsd; // ..
|
||||||
uInt encode; // encoding accumulator
|
uInt encode; // encoding accumulator
|
||||||
Int length; // coefficient length
|
Int length; // coefficient length
|
||||||
|
uByte buffer[ROUNDUP(DECPMAX+3, 4)]; // [+3 allows uInt padding]
|
||||||
|
|
||||||
#if DECCHECK
|
#if DECCHECK
|
||||||
Int clen=ulsd-umsd+1;
|
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
|
// fold down needed; must copy to buffer in order to pad
|
||||||
// with zeros safely; fortunately this is not the worst case
|
// with zeros safely; fortunately this is not the worst case
|
||||||
// path because cannot have had a round
|
// path because cannot have had a round
|
||||||
uByte buffer[ROUNDUP(DECPMAX+3, 4)]; // [+3 allows uInt padding]
|
|
||||||
uByte *s=umsd; // source
|
uByte *s=umsd; // source
|
||||||
uByte *t=buffer; // safe target
|
uByte *t=buffer; // safe target
|
||||||
uByte *tlsd=buffer+(ulsd-umsd)+shift; // target LSD
|
uByte *tlsd=buffer+(ulsd-umsd)+shift; // target LSD
|
||||||
@ -905,16 +905,20 @@ decFloat * decFloatFromString(decFloat *result, const char *string,
|
|||||||
else { // too long for buffer
|
else { // too long for buffer
|
||||||
// [This is a rare and unusual case; arbitrary-length input]
|
// [This is a rare and unusual case; arbitrary-length input]
|
||||||
// strip leading zeros [but leave final 0 if all 0's]
|
// 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]
|
const char* cfirst2=NULL;
|
||||||
for (; cfirst<clast; cfirst++) {
|
|
||||||
if (*cfirst!='0') { // non-zero found
|
for (; cfirst<=clast; cfirst++) {
|
||||||
if (*cfirst=='.') continue; // [ignore]
|
if (*cfirst == '.') continue; // [ignore]
|
||||||
break; // done
|
cfirst2=cfirst; // let's save the position of this digit
|
||||||
}
|
if (*cfirst!='0') break; // done
|
||||||
digits--; // 0 stripped
|
digits--; // 0 stripped
|
||||||
} // cfirst
|
} // 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
|
// the coefficient is now as short as possible, but may still
|
||||||
// be too long; copy up to Pmax+1 digits to the buffer, then
|
// be too long; copy up to Pmax+1 digits to the buffer, then
|
||||||
|
Loading…
Reference in New Issue
Block a user