From: Andy Heninger Date: Mon, 16 May 2016 21:57:34 +0000 (+0000) Subject: ICU-12532 Avoid potential memory mis-alignment of stack-allocated decNum instance. X-Git-Tag: milestone-59-0-1~432 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54b8f0c928503d63d69ce6f14f10c7028fdb193a;p=icu ICU-12532 Avoid potential memory mis-alignment of stack-allocated decNum instance. X-SVN-Rev: 38746 --- diff --git a/icu4c/source/i18n/visibledigits.cpp b/icu4c/source/i18n/visibledigits.cpp index a6cbd0fdce2..59832d6da0d 100644 --- a/icu4c/source/i18n/visibledigits.cpp +++ b/icu4c/source/i18n/visibledigits.cpp @@ -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();