mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-23 19:03:59 +08:00
73ad57c244
For the GNU locale model, codecvt::do_out and codecvt::do_in incorrectly return 'ok' when the destination range is empty. That happens because detecting incomplete output is done in the loop body, and the loop is never even entered if to == to_end. By restructuring the loop condition so that we check the output range separately, we can ensure that for a non-empty source range, we always enter the loop at least once, and detect if the destination range is too small. The loops also seem easier to reason about if we return immediately on any error, instead of checking the result twice on every iteration. We can use an RAII type to restore the locale before returning, which also simplifies all the other member functions. libstdc++-v3/ChangeLog: PR libstdc++/37475 * config/locale/gnu/codecvt_members.cc (Guard): New RAII type. (do_out, do_in): Return partial if the destination is empty but the source is not. Use Guard to restore locale on scope exit. Return immediately on any conversion error. (do_encoding, do_max_length, do_length): Use Guard. * testsuite/22_locale/codecvt/in/char/37475.cc: New test. * testsuite/22_locale/codecvt/in/wchar_t/37475.cc: New test. * testsuite/22_locale/codecvt/out/char/37475.cc: New test. * testsuite/22_locale/codecvt/out/wchar_t/37475.cc: New test. |
||
---|---|---|
.. | ||
abi | ||
allocator | ||
cpu | ||
io | ||
locale | ||
os |