Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mbsrtowcs() returns the number of wide char,but not the source in str… #4

Closed
wants to merge 1 commit into from

Conversation

hustterry
Copy link
Contributor

mbsrtowcs() returns the number of wide char,but not the source length.

If there have n chinese characters,the log will output more last n characters.

src/main/cpp/charsetdecoder.cpp
@@ -175,11 +175,11 @@ namespace log4cxx
stat = APR_BADARG;
in.position(src - in.data());
break;
} else {
stat = append(out, buf);

  •                           in.position(in.position() + converted);
    
  •                           in.position(in.position() + requested);
                          }
                     }
                 }
                 return stat;
             }
    

…ing length.

If there have n chinese characters,the log will output more last n characters.
@ams-tschoening
Copy link
Contributor

This has been reported before with different possible solutions. Is "requested" really correct compared to e.g. sizeof(...) * converted or such? Less than requested chars could have been processed in theory even without any error.

https://issues.apache.org/jira/browse/LOGCXX-369
https://issues.apache.org/jira/browse/LOGCXX-399

@ams-tschoening
Copy link
Contributor

It's a string by definition so I guess we can ignore problems with terminating 0 within the string before requested has been reached. Additionally, x * converted should be wrong as well because how many bytes one multibyte character spans depends on the current locale, right? So sounds safe to assume in case of success that simply all requested characters/bytes have been processed. This is reported to work in the linked issues as well:

Then I modified the "in.position(in.position() + converted);" to "in.position(in.position() + requested);"

https://issues.apache.org/jira/browse/LOGCXX-399?focusedCommentId=13969295&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-13969295

@asfgit asfgit closed this in 5f82518 Mar 21, 2018
@ams-tschoening
Copy link
Contributor

I fixed this using "requested" like mentioned in LOGCXX-399 and the linked PR #4 on GitHub. Additionally I added a test "decodingtest" using "encodingtest" as template, but the problem didn't occur using my C++Builder because I lack the used API, so am not sure if that works at all. It didn't fail before and doesn't now, so in the worst case is simply not doing anything useful. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants