From dac21eaf6cefc083d6acdc9707f0930e26891b9d Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Tue, 7 Dec 1999 00:35:36 +0000 Subject: [PATCH] ICU-174 ucmpXX_close(NULL) do not crash any more X-SVN-Rev: 327 --- icu4c/source/common/ucmp16.c | 46 +++++++++++++++++++++--------------- icu4c/source/common/ucmp32.c | 17 +++++++------ icu4c/source/common/ucmp8.c | 23 +++++++++--------- 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/icu4c/source/common/ucmp16.c b/icu4c/source/common/ucmp16.c index af2ecd0788c..8318a4642ca 100644 --- a/icu4c/source/common/ucmp16.c +++ b/icu4c/source/common/ucmp16.c @@ -199,31 +199,39 @@ CompactShortArray* ucmp16_openAlias(uint16_t *indexArray, void ucmp16_close(CompactShortArray* this_obj) { - if(this_obj->fAlias == FALSE) - { - icu_free(this_obj->fArray); - icu_free(this_obj->fIndex); + if(this_obj != NULL) { + if(!this_obj->fAlias) { + if(this_obj->fArray != NULL) { + icu_free(this_obj->fArray); + } + if(this_obj->fIndex != NULL) { + icu_free(this_obj->fIndex); + } + } + if(this_obj->fHashes != NULL) { + icu_free(this_obj->fHashes); + } + icu_free(this_obj); } - icu_free(this_obj->fHashes); - icu_free(this_obj); - - return; } CompactShortArray* setToBogus(CompactShortArray* this_obj) { - icu_free(this_obj->fArray); - this_obj->fArray = NULL; + if(this_obj != NULL) { + if(!this_obj->fAlias) { + icu_free(this_obj->fArray); + this_obj->fArray = NULL; - icu_free(this_obj->fIndex); - this_obj->fIndex = NULL; - - icu_free(this_obj->fHashes); - this_obj->fHashes = NULL; - - this_obj->fCount = 0; - this_obj->fCompact = FALSE; - this_obj->fBogus = TRUE; + icu_free(this_obj->fIndex); + this_obj->fIndex = NULL; + } + icu_free(this_obj->fHashes); + this_obj->fHashes = NULL; + + this_obj->fCount = 0; + this_obj->fCompact = FALSE; + this_obj->fBogus = TRUE; + } return this_obj; } diff --git a/icu4c/source/common/ucmp32.c b/icu4c/source/common/ucmp32.c index 8c63f6f75ad..406a5ecb8d1 100644 --- a/icu4c/source/common/ucmp32.c +++ b/icu4c/source/common/ucmp32.c @@ -196,17 +196,20 @@ CompactIntArray* ucmp32_openAdopt(uint16_t *indexArray, int32_t *newValues, int3 void ucmp32_close( CompactIntArray* this_obj) { - icu_free(this_obj->fArray); - this_obj->fArray = NULL; - icu_free(this_obj->fIndex); - this_obj->fIndex = NULL; - this_obj->fCount = 0; - this_obj->fCompact = FALSE; + if(this_obj != NULL) { + if(this_obj->fArray != NULL) { + icu_free(this_obj->fArray); + } + if(this_obj->fIndex != NULL) { + icu_free(this_obj->fIndex); + } + icu_free(this_obj); + } } bool_t ucmp32_isBogus(const CompactIntArray* this_obj) { - return this_obj->fBogus; + return this_obj == NULL || this_obj->fBogus; } void ucmp32_expand(CompactIntArray* this_obj) { diff --git a/icu4c/source/common/ucmp8.c b/icu4c/source/common/ucmp8.c index 57cf57ecf5d..1133bc7e28e 100644 --- a/icu4c/source/common/ucmp8.c +++ b/icu4c/source/common/ucmp8.c @@ -138,18 +138,17 @@ CompactByteArray* ucmp8_openAlias(uint16_t *indexArray, void ucmp8_close(CompactByteArray* this_obj) { - if(this_obj->fAlias == FALSE) - { - icu_free(this_obj->fArray); - icu_free(this_obj->fIndex); + if(this_obj != NULL) { + if(!this_obj->fAlias) { + if(this_obj->fArray != NULL) { + icu_free(this_obj->fArray); + } + if(this_obj->fIndex != NULL) { + icu_free(this_obj->fIndex); + } + } + icu_free(this_obj); } - - this_obj->fArray = NULL; - this_obj->fIndex = NULL; - this_obj->fCount = 0; - this_obj->fCompact = FALSE; - this_obj->fAlias = TRUE; - icu_free(this_obj); } @@ -239,7 +238,7 @@ findOverlappingPosition(CompactByteArray* this_obj, bool_t ucmp8_isBogus(const CompactByteArray* this_obj) { - return this_obj->fBogus; + return this_obj == NULL || this_obj->fBogus; } const int8_t*