Hello,
I maybe found a bug in the file “cacheddateformat.cpp” in function
“findMillisecondStart”. We have the for-loop in these loop it will be
check all characters of the formatted and the magicStrings. If
“formatted” and “plusMagic” string are different, there will be go to
check the current position (i) of the differents.
Have look at these in the code:
for (LogString::size_type i = 0; i < formatted.length(); i++)
if (formatted[i] != plusMagic[i]) {
if (plusZero.length() == formatted.length()
Now I have the values:
ConversionPattern %d{ yyyy-MM-dd HH:mm:ss,SSS}
formatted[i] → 2010-08-12 11:04:50,406/0
plusMagic[i] → 2010-08-12 11:04:50,654/0
plusZero → 2010-08-12 11:04:50,000/0
plusZero.length() → 23
formatted.length() → 23
i → 20
magicString → 654
formattedMillis → 406
zeroString → “”
On error I have these values:
ConversionPattern %d{ yyyy-MM-dd HH:mm:ss,SSS}
formatted[i] → 2010-08-12 11:04:50,609/0
plusMagic[i] → 2010-08-12 11:04:50,654/0
plusZero → 2010-08-12 11:04:50,000/0
plusZero.length() → 23
formatted.length() → 23
i → 21
magicString → 654
formattedMillis → 609
zeroString → “”
You used fixed values for the length of the magicString matching, but
if i use milliseconds in my appender, i will get troubles on different
times.
The length of our datetimestring is every time 23 characters. The
function will check if there have the values 000, 987 and 654. Where on
character found in the datetimestring you will get the position of them,
the value is mostly 20 but if we use milliseconds in the appender and
one of these was found we will get the position 21 or 22. The problem is
we have only 23 characters but the length of the magic string is every
time 3 and the function will read these characters that means we want to
read a character there not exist well position 23, 24 and 25 have no
values. The programm get an out_of_range error and exit.
&& regionMatches(magicString, 0, plusMagic, i, magicString.length())
magicString.length() is three..
&& regionMatches(formattedMillis, 0, formatted, i, magicString.length())
&& regionMatches(zeroString, 0, plusZero, i, 3)
Here we have the three to.
If the var i now 21 or 22 you will get this error well you only have 23
characters and you will read 24 or 25 characters.
I have a variant to fix that error.
@@ -137,12 +137,12 @@
//
//
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;
Now I have a question the name of the function “findMillisecondStart”
let me believe that I the caller the get the Position of the start of
the Milliseconds is it true?
If it is true than is that line wrong return i; here it must return the
startPostion of the milliseconds not the position of the sames? Or what
does the caller whits the returned value?
Best regards,
Richard Gericke
--
Richard Gericke
AM-SoFT IT-Systeme - Hameln | Potsdam | Leipzig
Telefon: Potsdam: 0331-743881-0
E-Mail: [email protected]
Web: http://www.am-soft.de
AM-SoFT GmbH IT-Systeme, Konsumhof 1-5, 14482 Potsdam
Amtsgericht Potsdam HRB 21278 P, Geschäftsführer: Andreas Muchow