]> granicus.if.org Git - icu/commitdiff
ICU-13717 During SimpleDateFormat#parseInt, avoid cloning the DecimalFormat unless...
authorShane Carr <shane@unicode.org>
Wed, 23 May 2018 04:21:24 +0000 (04:21 +0000)
committerShane Carr <shane@unicode.org>
Wed, 23 May 2018 04:21:24 +0000 (04:21 +0000)
X-SVN-Rev: 41440

icu4c/source/i18n/smpdtfmt.cpp

index 210e7db1a29a0a2b4ef7e4dd0bd4c581c4453032..b1b90882fceeadd7d82542b9e2013212df51e116 100644 (file)
@@ -3754,21 +3754,19 @@ void SimpleDateFormat::parseInt(const UnicodeString& text,
                                 UBool allowNegative,
                                 const NumberFormat *fmt) const {
     UnicodeString oldPrefix;
-    const DecimalFormat* fmtAsDF = dynamic_cast<const DecimalFormat*>(fmt);
+    auto* fmtAsDF = dynamic_cast<const DecimalFormat*>(fmt);
     LocalPointer<DecimalFormat> df;
-    if (fmtAsDF != nullptr) {
+    if (!allowNegative && fmtAsDF != nullptr) {
         df.adoptInstead(dynamic_cast<DecimalFormat*>(fmtAsDF->clone()));
-    }
-    if (!allowNegative && !df.isNull()) {
-        fmt = df.getAlias();
-        df->getNegativePrefix(oldPrefix);
+        if (df.isNull()) {
+            // Memory allocation error
+            return;
+        }
         df->setNegativePrefix(UnicodeString(TRUE, SUPPRESS_NEGATIVE_PREFIX, -1));
+        fmt = df.getAlias();
     }
     int32_t oldPos = pos.getIndex();
     fmt->parse(text, number, pos);
-    if (!df.isNull()) {
-        df->setNegativePrefix(oldPrefix);
-    }
 
     if (maxDigits > 0) {
         // adjust the result to fit into