From 6e059f147566afe7a1a248082d8c4a4211aec35b Mon Sep 17 00:00:00 2001 From: Vladimir Weinstein Date: Fri, 6 Jun 2003 05:05:37 +0000 Subject: [PATCH] ICU-2974 disallow new X[0] X-SVN-Rev: 12343 --- icu4c/source/common/locid.cpp | 41 ++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/icu4c/source/common/locid.cpp b/icu4c/source/common/locid.cpp index 322dec18bf..e2972dc0cd 100644 --- a/icu4c/source/common/locid.cpp +++ b/icu4c/source/common/locid.cpp @@ -732,28 +732,33 @@ Locale::getAvailableLocales(int32_t& count) if (needInit) { int32_t locCount = uloc_countAvailable(); - Locale *newLocaleList = new Locale[locCount]; - if (newLocaleList == NULL) { - return NULL; - } + if(locCount) { + Locale *newLocaleList = new Locale[locCount]; + if (newLocaleList == NULL) { + return NULL; + } - count = locCount; + count = locCount; - while(--locCount >= 0) { - newLocaleList[locCount].setFromPOSIXID(uloc_getAvailable(locCount)); - } + while(--locCount >= 0) { + newLocaleList[locCount].setFromPOSIXID(uloc_getAvailable(locCount)); + } - umtx_lock(NULL); - if(availableLocaleList == 0) { - availableLocaleListCount = count; - availableLocaleList = newLocaleList; - newLocaleList = NULL; - } - umtx_unlock(NULL); - delete []newLocaleList; + umtx_lock(NULL); + if(availableLocaleList == 0) { + availableLocaleListCount = count; + availableLocaleList = newLocaleList; + newLocaleList = NULL; + } + umtx_unlock(NULL); + delete []newLocaleList; + } + count = availableLocaleListCount; + return availableLocaleList; + } else { + count = 0; + return NULL; } - count = availableLocaleListCount; - return availableLocaleList; } const char* const* Locale::getISOCountries()