libstdc++: Avoid bad_alloc exceptions when changing locales
authorJonathan Wakely <jwakely@redhat.com>
Tue, 10 Nov 2020 19:23:15 +0000 (19:23 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 10 Nov 2020 20:33:29 +0000 (20:33 +0000)
commit5dfbc52264fc64db22e75f385be9efae3d0eba46
tree3aa5fecbf586d5d5e85e46c42fa46b1177f0e4b3
parent8c0c83feb04d7486ccf9cbe86dcd5668f0a21ef9
libstdc++: Avoid bad_alloc exceptions when changing locales

For the --enable-clocale=generic configuration, the current code can
fail with a bad_alloc exception. This patch uses the nothrow version of
operator new and reports allocation failures by setting failbit in the
iostate variable.

* config/locale/generic/c_locale.cc (__set_C_locale()): New function
to set the "C" locale and return the name of the previous locale.
(__convert_to_v<float>, __convert_to_v<double>)
(__convert_to_v<long double>): Use __set_C_locale and set failbit on
error.
libstdc++-v3/config/locale/generic/c_locale.cc