Bug 441639 - libstdc++-v3 locale - collate and time swapped
Summary: libstdc++-v3 locale - collate and time swapped
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: gcc
Version: 5.2
Hardware: All
OS: Linux
low
low
Target Milestone: rc
: ---
Assignee: Jakub Jelinek
QA Contact:
URL: http://gcc.gnu.org/bugzilla/show_bug....
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-04-09 09:14 UTC by Andrew Mann
Modified: 2009-01-20 21:25 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2009-01-20 21:25:04 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Apply upstream fix for GCC PR29217 (1.10 KB, patch)
2008-04-09 09:14 UTC, Andrew Mann
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 29217 0 None None None Never
Red Hat Product Errata RHBA-2009:0157 0 normal SHIPPED_LIVE gcc bug-fix update 2009-01-20 16:05:12 UTC

Description Andrew Mann 2008-04-09 09:14:37 UTC
Description of problem:
In gnu libstdc++v3 within gcc 4.1.1/4.1.2, the numerical encoding of the time
and collate categories are swapped. This results in programs that individually
set locale categories using std::locale::collate or std::locale::time to operate
incorrectly when run on RHEL5 (or when built on RHEL5 and static linked to
libstdc++). This has been fixed in gcc 4.2.0 but not yet backported into RHEL5
gcc 4.1.2.


Version-Release number of selected component (if applicable): 4.1.2-14.el5


How reproducible: Always.


Steps to Reproduce:

The following short program demonstrates the problem:

#include <iostream>
#include <string>
#include <ctime>
#include <sstream>

using namespace std;

locale SetCppLocale()
{
    locale loc;
    locale temp(std::locale::classic(), "en_US.UTF-8", std::locale::collate );
    locale oldLoc = std::locale::global(temp);

    return oldLoc;
}

string DoDateTimeString()
{
  time_t utcTime;
  time(&utcTime);
  struct tm *time = localtime(&utcTime);
  char buffer[300];
  strftime(buffer, 300, "%c", time);
  return string(buffer);
}

int main()
{
  string time = DoDateTimeString();
  cout << "Time in default locale: " << time << endl;

  locale oldLoc = SetCppLocale();
  cout << "Old locale name: " << oldLoc.name() << endl;
  locale newLoc;
  cout << "New locale name: " << newLoc.name() << endl;

  time = DoDateTimeString();
  cout << "Time in hybrid locale: " << time << endl;

  return 0;
}


 
Actual results:

(generated from RHEL5 w/ latest gcc errata)

Time in default locale: Wed Apr  9 04:59:41 2008
Old locale name: C
New locale name:
LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C
Time in hybrid locale: Wed 09 Apr 2008 04:59:41 AM EDT

Note that only std::locale::collate was set, and NOT std::locale::time . In the
resulting locale name, LC_TIME has been changed to en_US.UTF-8 instead of
LC_COLLATE.  The current time display lines show that this is not just a name
string output bug, but affects locale handling of dates as well.


Expected results:

(generated from patched system)

Time in default locale: Wed Apr  9 04:55:50 2008
Old locale name: C
New locale name:
LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C
Time in hybrid locale: Wed Apr  9 04:55:50 2008


Additional info:

This bug is fixed in gcc 4.2.0 and is described at
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29217


The attached patch applies the same workaround code from gcc mainline to the
RHEL5 gcc-4.1.2-14.el5 source.

Comment 1 Andrew Mann 2008-04-09 09:14:37 UTC
Created attachment 301764 [details]
Apply upstream fix for GCC PR29217

Comment 2 RHEL Program Management 2008-06-02 20:09:04 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 9 errata-xmlrpc 2009-01-20 21:25:04 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2009-0157.html


Note You need to log in before you can comment on or make changes to this bug.