]> granicus.if.org Git - icu/commitdiff
ICU-12704 change dtptngen.cpp to use LocalMemory<int32_t> instead of LocalArray
authorSteven R. Loomis <srl@icu-project.org>
Wed, 31 Aug 2016 23:36:19 +0000 (23:36 +0000)
committerSteven R. Loomis <srl@icu-project.org>
Wed, 31 Aug 2016 23:36:19 +0000 (23:36 +0000)
LocalArray cannot be used with primitive types.

X-SVN-Rev: 39114

icu4c/source/i18n/dtptngen.cpp

index 6196803b72ce1cc65e48df13aca28389e6f1e0fd..e680ee4f884ddb4b5ff4fdc3a2da0326e9d3f220 100644 (file)
@@ -445,21 +445,23 @@ struct AllowedHourFormatsSink : public ResourceSink {
             if (U_FAILURE(errorCode)) { return; }
             for (int32_t j = 0; formatList.getKeyAndValue(j, key, value); ++j) {
                 if (uprv_strcmp(key, "allowed") == 0) {  // Ignore "preferred" list.
-                    LocalArray<int32_t> list;
+                    LocalMemory<int32_t> list;
                     int32_t length;
                     if (value.getType() == URES_STRING) {
-                        list.adoptInsteadAndCheckErrorCode(
-                            static_cast<int32_t *>(uprv_malloc(2 * sizeof(int32_t))), errorCode);
-                        if (U_FAILURE(errorCode)) { return; }
+                        if (list.allocateInsteadAndReset(2) == NULL) { 
+                                                       errorCode = U_MEMORY_ALLOCATION_ERROR;
+                                                       return;
+                                               }
                         list[0] = getHourFormatFromUnicodeString(value.getUnicodeString(errorCode));
                         length = 1;
                     } else {
                         ResourceArray allowedFormats = value.getArray(errorCode);
                         length = allowedFormats.getSize();
-                        list.adoptInsteadAndCheckErrorCode(
-                            static_cast<int32_t *>(uprv_malloc((length + 1) * sizeof(int32_t))), errorCode);
-                        if (U_FAILURE(errorCode)) { return; }
-                        for (int32_t k = 0; k < length; ++k) {
+                                               if (list.allocateInsteadAndReset(length+1) == NULL) {
+                                                       errorCode = U_MEMORY_ALLOCATION_ERROR;
+                                                       return;
+                                               }
+                                               for (int32_t k = 0; k < length; ++k) {
                             allowedFormats.getValue(k, value);
                             list[k] = getHourFormatFromUnicodeString(value.getUnicodeString(errorCode));
                         }