Author: tschoening Date: Sun Jan 19 16:45:50 2014 New Revision: 1559522 URL: http://svn.apache.org/r1559522 Log: LOG4CXX-420: CachedDateFormat::findMillisecondStart may have thorwn out_of_range exceptions if the compared milliseconds started with the same number.
Modified: incubator/log4cxx/trunk/src/main/cpp/cacheddateformat.cpp Modified: incubator/log4cxx/trunk/src/main/cpp/cacheddateformat.cpp URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/cpp/cacheddateformat.cpp?rev=1559522&r1=1559521&r2=1559522&view=diff ============================================================================== --- incubator/log4cxx/trunk/src/main/cpp/cacheddateformat.cpp (original) +++ incubator/log4cxx/trunk/src/main/cpp/cacheddateformat.cpp Sun Jan 19 16:45:50 2014 @@ -134,15 +134,13 @@ int CachedDateFormat::findMillisecondSta // If the next 3 characters match the magic // strings and the remaining fragments are identical - // - // if (plusZero.length() == formatted.length() - && regionMatches(magicString, 0, plusMagic, i, magicString.length()) - && regionMatches(formattedMillis, 0, formatted, i, magicString.length()) - && regionMatches(zeroString, 0, plusZero, i, 3) - && (formatted.length() == i + 3 - || plusZero.compare(i + 3, - LogString::npos, plusMagic, i+3, LogString::npos) == 0)) { + && regionMatches(magicString, magicString.length() - (plusMagic.length() - i), plusMagic, i, plusMagic.length() - i) + && regionMatches(formattedMillis, formattedMillis.length() - (formatted.length() - i), formatted, i, formatted.length() - i) + && regionMatches(zeroString, (sizeof(zeroString)/sizeof(zeroString[0]) - 1) - (plusZero.length() - i), plusZero, i, plusZero.length() - i) + && (formatted.length() == i + (formatted.length() - i) + || plusZero.compare(i + (plusZero.length() - i), + LogString::npos, plusMagic, i + (plusMagic.length() - i), LogString::npos) == 0)) { return i; } else { return UNRECOGNIZED_MILLISECONDS;