[Boost-bugs] [Boost C++ Libraries] #3634: to_upper / to_lower incorrect for machines with signed chars

Subject: [Boost-bugs] [Boost C++ Libraries] #3634: to_upper / to_lower incorrect for machines with signed chars
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-11-18 07:40:41


#3634: to_upper / to_lower incorrect for machines with signed chars
-----------------------------------------------------+----------------------
 Reporter: Thomas Dorner <td-eclipse@…> | Owner: pavol_droba
     Type: Bugs | Status: new
Milestone: Boost 1.41.0 | Component: string_algo
  Version: Boost 1.40.0 | Severity: Problem
 Keywords: |
-----------------------------------------------------+----------------------
 I'm using an ISO8859-1 / ISO8859-15 (Latin-1 / Latin-9) character set for
 the source and a string containing german umlauts is not correctly
 converted according to the locale configuration. The problem is
 reproducible on any machine where the default configuration of C/C++ uses
 signed chars, in our case Sun Solaris:

 1.
 The conversion functions toupper and tolower of the standard C library
 expect an int parameter.

 2.
 Solaris' characters are signed by default (and Sun explicitly advises
 against changing that, the manpage of Sunstudio 12.1' CC says about the
 -xchar option:

 "It is strongly recommended that you never use -xchar to compile routines
 for any interface exported through a library. The Solaris ABI specifies
 type char as signed, and system libraries behave accordingly. The effect
 of making char unsigned has not been extensively tested with system
 libraries. Instead of using this option, modify your code so that it does
 not depend on whether type char is signed or unsigned. The sign of type
 char varies among compilers and operating systems.")

 3.
 Characters with an unsinged value >= 128 (e.g. an umlaut) have negative
 values for toupper and tolower and thus are never converted for any
 locale.

 An explicit static cast to unsigned character in the calls to the
 according standard C libraries function should solve this problem.

 Note that this may also be needed for other functions as well, e.g. the
 classification function. I didn't check those so far.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3634>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:01 UTC