diff --git a/icu4c/source/test/intltest/intltest.cpp b/icu4c/source/test/intltest/intltest.cpp index 68ae1749a8..e39a2a0e23 100644 --- a/icu4c/source/test/intltest/intltest.cpp +++ b/icu4c/source/test/intltest/intltest.cpp @@ -1345,22 +1345,20 @@ const char * IntlTest::pathToDataDirectory() strcpy(p, __FILE__); /* We want to back over three '\' chars. */ /* Only Windows should end up here, so looking for '\' is safe. */ - if (strrchr(p, U_FILE_SEP_CHAR) != NULL) { - for (i=1; i<=3; i++) { - pBackSlash = strrchr(p, U_FILE_SEP_CHAR); - if (pBackSlash != NULL) { - *pBackSlash = 0; /* Truncate the string at the '\' */ - } - } - + for (i=1; i<=3; i++) { + pBackSlash = strrchr(p, U_FILE_SEP_CHAR); if (pBackSlash != NULL) { - /* We found and truncated three names from the path. - * Now append "source\data" and set the environment - */ - strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING ); - fgDataDir = p; + *pBackSlash = 0; /* Truncate the string at the '\' */ } } + + if (pBackSlash != NULL) { + /* We found and truncated three names from the path. + * Now append "source\data" and set the environment + */ + strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING ); + fgDataDir = p; + } else { /* __FILE__ on MSVC7 does not contain the directory */ fgDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;