]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/gensprep/store.c
ICU-491.11.3.tar.gz
[apple/icu.git] / icuSources / tools / gensprep / store.c
index 58b88b3ae7c6309ce87b596a1bf58e334d6ecb3f..49ea02eb5f7bdd78e1ba9add1b48ebcc1c4d2ad8 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 1999-2006, International Business Machines
+*   Copyright (C) 1999-2012, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -22,6 +22,7 @@
 #include "cstring.h"
 #include "filestrm.h"
 #include "unicode/udata.h"
+#include "unicode/utf16.h"
 #include "utrie.h"
 #include "unewdata.h"
 #include "gensprep.h"
@@ -196,8 +197,7 @@ static UNewTrie *sprepTrie;
 extern void
 init() {
 
-    sprepTrie = (UNewTrie *)uprv_malloc(sizeof(UNewTrie));
-    uprv_memset(sprepTrie, 0, sizeof(UNewTrie));
+    sprepTrie = (UNewTrie *)uprv_calloc(1, sizeof(UNewTrie));
 
     /* initialize the two tries */
     if(NULL==utrie_open(sprepTrie, NULL, MAX_DATA_LENGTH, 0, 0, FALSE)) {
@@ -240,17 +240,20 @@ storeMappingData(){
     const UHashElement* element = NULL;
     ValueStruct* value  = NULL;
     int32_t codepoint = 0;
-    int32_t elementCount = uhash_count(hashTable);
+    int32_t elementCount = 0;
     int32_t writtenElementCount = 0;
     int32_t mappingLength = 1; /* minimum mapping length */
     int32_t oldMappingLength = 0;
     uint16_t trieWord =0;
     int32_t limitIndex = 0;
 
-    /*initialize the mapping data */
-    mappingData = (uint16_t*) uprv_malloc(U_SIZEOF_UCHAR * (mappingDataCapacity));
+    if (hashTable == NULL) {
+        return;
+    }
+    elementCount = uhash_count(hashTable);
 
-    uprv_memset(mappingData,0,U_SIZEOF_UCHAR * mappingDataCapacity);
+       /*initialize the mapping data */
+    mappingData = (uint16_t*) uprv_calloc(mappingDataCapacity, U_SIZEOF_UCHAR);
 
     while(writtenElementCount < elementCount){
 
@@ -453,17 +456,15 @@ storeMapping(uint32_t codepoint, uint32_t* mapping,int32_t length,
          */
     }
 
-    map = (UChar*) uprv_malloc(U_SIZEOF_UCHAR * (adjustedLen+1));
-    uprv_memset(map,0,U_SIZEOF_UCHAR * (adjustedLen+1));
-
+    map = (UChar*) uprv_calloc(adjustedLen + 1, U_SIZEOF_UCHAR);
     i=0;
     
     while(i<length){
         if(mapping[i] <= 0xFFFF){
             map[i] = (uint16_t)mapping[i];
         }else{
-            map[i]   = UTF16_LEAD(mapping[i]);
-            map[i+1] = UTF16_TRAIL(mapping[i]);
+            map[i]   = U16_LEAD(mapping[i]);
+            map[i+1] = U16_TRAIL(mapping[i]);
         }
         i++;
     }
@@ -550,12 +551,10 @@ storeRange(uint32_t start, uint32_t end, UStringPrepType type,UErrorCode* status
 /* folding value: just store the offset (16 bits) if there is any non-0 entry */
 static uint32_t U_CALLCONV
 getFoldedValue(UNewTrie *trie, UChar32 start, int32_t offset) {
-    uint32_t foldedValue, value;
+    uint32_t value;
     UChar32 limit=0;
     UBool inBlockZero;
 
-    foldedValue=0;
-
     limit=start+0x400;
     while(start<limit) {
         value=utrie_get32(trie, start, &inBlockZero);
@@ -647,7 +646,9 @@ generateData(const char *dataDir, const char* bundleName) {
 
 #if !UCONFIG_NO_IDNA
     /* done with writing the data .. close the hashtable */
-    uhash_close(hashTable);
+    if (hashTable != NULL) {
+        uhash_close(hashTable);
+    }
 #endif
 }