U_ASSERT(destIdx >= 0);
int32_t length = MAX_IDX - destIdx -1;
/*int32_t prefixLen = */ appendAffix(appendTo, static_cast<double>(number), handler, number<0, TRUE);
+
+ // This will be at least 0 even if it was set to a negative number.
int32_t maxIntDig = getMaximumIntegerDigits();
int32_t destlength = length<=maxIntDig?length:maxIntDig; // dest length pinned to max int digits
status = U_ILLEGAL_ARGUMENT_ERROR;
}
- int32_t prependZero = getMinimumIntegerDigits() - destlength;
+ int32_t minDigits = getMinimumIntegerDigits();
+
+ // We always want at least one digit, even if it is just a 0.
+ int32_t prependZero = (minDigits < 1 ? 1 : minDigits) - destlength;
#ifdef FMT_DEBUG
printf("prependZero=%d, length=%d, minintdig=%d maxintdig=%d destlength=%d skip=%d\n", prependZero, length, getMinimumIntegerDigits(), maxIntDig, destlength, length-destlength);
/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2014, International Business Machines Corporation and
+ * Copyright (c) 1997-2015, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/* Modification History:
TESTCASE_AUTO(TestEquality);
TESTCASE_AUTO(TestCurrencyUsage);
TESTCASE_AUTO(TestDoubleLimit11439);
+ TESTCASE_AUTO(TestFastPathConsistent11524);
TESTCASE_AUTO_END;
}
}
}
+void NumberFormatTest::TestFastPathConsistent11524() {
+ UErrorCode status = U_ZERO_ERROR;
+ NumberFormat *fmt = NumberFormat::createInstance("en", status);
+ fmt->setMaximumIntegerDigits(INT32_MIN);
+ UnicodeString appendTo;
+ assertEquals("", "0", fmt->format(123, appendTo));
+ appendTo.remove();
+ assertEquals("", "0", fmt->format(12345, appendTo));
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */
/************************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2014, International Business Machines Corporation
+ * Copyright (c) 1997-2015, International Business Machines Corporation
* and others. All Rights Reserved.
************************************************************************/
void TestCurrencyUsage();
void TestDoubleLimit11439();
+ void TestFastPathConsistent11524();
private:
UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);