From a31b3bcb5b8249b405569b9490955edfa06ad3bd Mon Sep 17 00:00:00 2001 From: Dmitry Kovalenko Date: Tue, 30 May 2023 13:25:22 +0300 Subject: [PATCH] The part of fix #7599. Problems with pointers in decNumber library (#7607) * 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 f5af6a92c6edd98eda36a295206d94c1ed75a986) --- extern/decNumber/decCommon.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/extern/decNumber/decCommon.c b/extern/decNumber/decCommon.c index 6a0c112c88..e16d6ee2d1 100644 --- a/extern/decNumber/decCommon.c +++ b/extern/decNumber/decCommon.c @@ -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