From d83f32e6415827117ba78b2872416189867c8471 Mon Sep 17 00:00:00 2001 From: Peter Edberg Date: Thu, 13 May 2010 03:35:54 +0000 Subject: [PATCH] ICU-7550 udat_setSymbols should call verifyIsSimpleDateFormat to avoid crash with RelativeDateFormat X-SVN-Rev: 28057 --- icu4c/source/i18n/udat.cpp | 4 ++-- icu4c/source/test/cintltst/cdattst.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/icu4c/source/i18n/udat.cpp b/icu4c/source/i18n/udat.cpp index ffc81d0999e..cb59e47c1de 100644 --- a/icu4c/source/i18n/udat.cpp +++ b/icu4c/source/i18n/udat.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1996-2009, International Business Machines +* Copyright (C) 1996-2010, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* */ @@ -783,7 +783,7 @@ udat_setSymbols( UDateFormat *format, int32_t valueLength, UErrorCode *status) { - + verifyIsSimpleDateFormat(format, status); if(U_FAILURE(*status)) return; DateFormatSymbols *syms = (DateFormatSymbols *)((SimpleDateFormat *)format)->getDateFormatSymbols(); diff --git a/icu4c/source/test/cintltst/cdattst.c b/icu4c/source/test/cintltst/cdattst.c index 697f34d74bb..e06bd904909 100644 --- a/icu4c/source/test/cintltst/cdattst.c +++ b/icu4c/source/test/cintltst/cdattst.c @@ -1201,6 +1201,18 @@ static void TestRelativeCrash(void) { log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what, u_errorName(subStatus), u_errorName(expectStatus)); } } + { + UErrorCode subStatus = U_ZERO_ERROR; + UChar symbolValue = 0x0041; + what = "udat_setSymbols"; + log_verbose("Trying %s on a relative date..\n", what); + udat_setSymbols(icudf, UDAT_ERAS,0,&symbolValue,1, &subStatus); /* bogus values */ + if(subStatus == expectStatus) { + log_verbose("Success: did not crash on %s, but got %s.\n", what, u_errorName(subStatus)); + } else { + log_err("FAIL: didn't crash on %s, but got success %s instead of %s. \n", what, u_errorName(subStatus), u_errorName(expectStatus)); + } + } { UErrorCode subStatus = U_ZERO_ERROR; what = "udat_countSymbols";