locale bug?

Jason Pyeron jpyeron@pdinc.us
Mon May 17 14:11:25 GMT 2021


While working an updated build of pdfgrep, I ran in to a crash when the environment local was something other than LC_ALL=C.

 

Looking at http://www.cplusplus.com/reference/locale/locale/locale/ the empty string passed to the constructor should use the environment's default locale and if the “argument” does not represent a valid C-locale in the implementation, runtime_error is thrown.

 

 

$ g++ -o bug50 bug50.cc ; echo en_US.UTF-8; LC_ALL="en_US.UTF-8" ./bug50; echo C; LC_ALL=C ./bug50

en_US.UTF-8

Line:8:start

Line:17:exception thrown

Line:19:succeeded using Minimal C locale (the same as locale::classic)

Line:21:about to set global locale

Line:23:done

C

Line:8:start

Line:13:succeeded using The environment's default locale

Line:21:about to set global locale

Line:23:done

 

$ cat -n bug50.cc

     1  #include <iostream>

     2  #include <locale>

     3

     4  using namespace std;

     5

     6  int main(int argc, char** argv)

     7  {

     8          cout << "Line:" << __LINE__ << ":start" << endl;

     9          locale l;

    10          try

    11          {

    12                  l=locale("");

    13                  cout << "Line:" << __LINE__ << ":succeeded using The environment's default locale" << endl;

    14          }

    15          catch (exception& e)

    16          {

    17                  cout << "Line:" << __LINE__ << ":exception thrown" << endl;

    18                  l=locale("C");

    19                  cout << "Line:" << __LINE__ << ":succeeded using Minimal C locale (the same as locale::classic)" << endl;

    20          }

    21          cout << "Line:" << __LINE__ << ":about to set global locale" << endl;

    22          locale::global(l);

    23          cout << "Line:" << __LINE__ << ":done" << endl;

    24

    25  }

 

Thoughts? This is out of my knowledge area – never worked with locales in C++ before.



More information about the Cygwin mailing list