ICU-1220 protect against undocumented error codes which crash us.

X-SVN-Rev: 7691
This commit is contained in:
Yves Arrouye 2002-02-16 08:59:44 +00:00
parent 3aa83e6566
commit 4566ade726

View File

@ -198,17 +198,24 @@ U_CAPI const UChar *u_wmsg_errorName(UErrorCode err)
}
else
{
msg = (UChar*)ures_getStringByKey(gBundle, u_errorName(err), &msgLen, &subErr);
if(U_FAILURE(subErr))
{
msg = NULL;
const char *errname = u_errorName(err);
if (errname) {
msg = (UChar*)ures_getStringByKey(gBundle, errname, &msgLen, &subErr);
if(U_FAILURE(subErr))
{
msg = NULL;
}
}
}
if(msg == NULL) /* Couldn't find it anywhere.. */
{
char error[128];
textMsg = u_errorName(err);
if (!textMsg) {
sprintf(error, "UNDOCUMENTED ICU ERROR %d", err);
textMsg = error;
}
msg = (UChar*)malloc((strlen(textMsg)+1)*sizeof(msg[0]));
u_charsToUChars(textMsg, msg, strlen(textMsg)+1);
}