delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2021/05/17/10:11:31

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 810D63835821
Authentication-Results: sourceware.org;
dmarc=none (p=none dis=none) header.from=pdinc.us
Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jpyeron AT pdinc DOT us
DKIM-Filter: OpenDKIM Filter v2.11.0 mail2.pdinc.us 14HEBEKU008944
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pdinc.us; s=default;
t=1621260675; bh=2Wy098yppf7lCbbG0KUGMUrf4yxveilY+tY+TMCHG4Q=;
h=From:To:Subject:Date:From;
b=ivhgUWFZvE6hViDXuLk+0CPvvO3YknXdjQiq4g9cLr1y+7SJs5eDqzgoEm2r0Gns5
zPJyj4F9eCcPvKMobnTBOZBzF9n0AzMY5vD0mMRItV5pTvZYJV9r7E+msFQ/p4mwaa
bgDJm28N/wIqcmDkpXytq0myaatsUL4wtO9nDobYBn9N0D+Kp+FDMhEYGzqQcVJhZR
ml43IW3N/Mafx1WQe+3rS3Q32IkoSDWCG/4ORJe7MAfuM8AGj3g1LcAe0V2QcCDH1H
FR+RZvVz86vTnQXgYIQyZfxrtkfFGt7rclwbvMvoyFGKzTjYqw/DtuQM8A1xgsktPE
q1b4RHzt5VhbQ==
From: "Jason Pyeron" <jpyeron AT pdinc DOT us>
To: <cygwin AT cygwin DOT com>
Subject: locale bug?
Date: Mon, 17 May 2021 10:11:25 -0400
Message-ID: <062101d74b26$85d13600$9173a200$@pdinc.us>
MIME-Version: 1.0
X-Mailer: Microsoft Outlook 15.0
Thread-Index: AddLJoVf+mAnMNzPQ12/4ZINMrSd2g==
X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, HTML_MESSAGE, KAM_INFOUSMEBIZ,
SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
server2.sourceware.org
X-Content-Filtered-By: Mailman/MimeDel 2.1.29
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
Sender: "Cygwin" <cygwin-bounces AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 14HEBVWZ007596

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.


-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019