ICU-12532 Avoid potential memory mis-alignment of stack-allocated decNum instance.

X-SVN-Rev: 38746
This commit is contained in:
Andy Heninger 2016-05-16 21:57:34 +00:00
parent 6cc82d7089
commit 54b8f0c928

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, International Business Machines
* Copyright (C) 2016, International Business Machines
* Corporation and others. All Rights Reserved.
*
* file name: visibledigits.cpp
@ -84,8 +84,11 @@ double VisibleDigits::computeAbsDoubleValue() const {
}
// stack allocate a decNumber to hold MAX_DBL_DIGITS+3 significant digits
char rawNumber[sizeof(decNumber) + MAX_DBL_DIGITS+3];
decNumber *numberPtr = (decNumber *) rawNumber;
struct {
decNumber decNum;
char digits[MAX_DBL_DIGITS+3];
} decNumberWithStorage;
decNumber *numberPtr = &decNumberWithStorage.decNum;
int32_t mostSig = fInterval.getMostSignificantExclusive();
int32_t mostSigNonZero = fExponent + fDigits.length();