[Boost-bugs] [Boost C++ Libraries] #5507: const char vs. const signed char in boost/archive/iterators/binary_from_base64.hpp

Subject: [Boost-bugs] [Boost C++ Libraries] #5507: const char vs. const signed char in boost/archive/iterators/binary_from_base64.hpp
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-04-27 13:40:28


#5507: const char vs. const signed char in
boost/archive/iterators/binary_from_base64.hpp
---------------------------------------------------------+------------------
 Reporter: Gernot Hillier <gernot.hillier@…> | Owner: ramey
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: serialization
  Version: Boost 1.46.1 | Severity: Problem
 Keywords: |
---------------------------------------------------------+------------------
 There seems to be a small bug in binary_from_base64.hpp:

 {{{
      CharType operator()(CharType t) const{
         const char lookup_table[] = {
              -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
      [...]
 }}}

 However, it's not guaranteed that a "const char" accepts signed values,
 see e.g. http://www.network-theory.co.uk/docs/gccintro/gccintro_71.html.
 See also /usr/include/limits.h - depending whether {{{__CHAR_UNSIGNED__}}}
 is set or not, the platform may not or may accept negative values for a
 const char.

 Especially when enabling C++0x support, this leads to a compilation
 failure e.g. on PowerPC:

 {{{
 "powerpc-linux-gnu-g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-
 inline -Wall -pthread -fPIC -std=c++0x -DBOOST_ALL_NO_LIB=1
 -DBOOST_SERIALIZATION_DYN_LINK=1 -DNDEBUG -I"." -c -o
 "bin.v2/libs/serialization/build/gcc-powerpc/release/threading-
 multi/basic_text_iprimitive.o"
 "libs/serialization/src/basic_text_iprimitive.cpp"
 [...]
 In file included from ./boost/archive/impl/basic_text_iprimitive.ipp:30:0,
                  from libs/serialization/src/basic_text_iprimitive.cpp:19:
 [...]
 ./boost/archive/iterators/binary_from_base64.hpp:51:9: error: narrowing
 conversion of '-0x00000000000000001' from 'int' to 'const char' inside { }
 }}}

 The following patch fixed the problem for us:

 {{{
 Index: boost_1_46_1/boost/archive/iterators/binary_from_base64.hpp
 ===================================================================
 --- boost_1_46_1.orig/boost/archive/iterators/binary_from_base64.hpp
 +++ boost_1_46_1/boost/archive/iterators/binary_from_base64.hpp
 @@ -39,7 +39,7 @@ template<class CharType>
  struct to_6_bit {
      typedef CharType result_type;
      CharType operator()(CharType t) const{
 - const char lookup_table[] = {
 + const signed char lookup_table[] = {
              -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
              -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
              -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5507>
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:06 UTC