[PATCH,AIX] ctype_inline.h cast and thread-safe access to __lc_type

David Edelsohn dje.gcc@gmail.com
Wed Jan 20 23:04:01 GMT 2021


   aix: make ctype_inline.h thread-safe and avoid _OBJ_DATA char subscript.

    g++.dg/warn/Wstringop-overflow-6.C tests for a bogus overflow warning in
    system headers.  This testcase was generating a -Wchar-subscript warning
    on AIX because ctype_inline.h was subscripting AIX _OBJ_DATA using a char.
    The _M_table case cast the subscript to unsigned char, but the _OBJ_DATA
    case did not.

    The investigation also exposed that AIX has added a thread-safe variant
    of access to __lc_type that had not been applied to the libstdc++
    implementation.

    This patch casts the subscript to unsigned char and adds the THREAD_SAFE
    variant.  libstdc++ always is compiled with pthreads, but it is good
    to make the situation explicit and to document the appropriate usage.

    Bootstrapped on powerpc-ibm-aix7.2.3.0.

            * config/os/aix/ctype_inline.h (bool ctype<char>:: is): Cast
            _OBJ_DATA subscript to unsigned char. Add _THREAD_SAFE access to
            __lc_type.
            (const char* ctype<char>:: is): Same.

diff --git a/libstdc++-v3/config/os/aix/ctype_inline.h
b/libstdc++-v3/config/os/aix/ctype_inline.h
index 1faa19d8678..696fcfbf85a 100644
--- a/libstdc++-v3/config/os/aix/ctype_inline.h
+++ b/libstdc++-v3/config/os/aix/ctype_inline.h
@@ -45,7 +45,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     if(_M_table)
       return _M_table[static_cast<unsigned char>(__c)] & __m;
     else
-      return __OBJ_DATA(__lc_ctype)->mask[__c] & __m;
+#ifdef _THREAD_SAFE
+      return __OBJ_DATA((*__lc_ctype_ptr))->mask[static_cast<unsigned
char>(__c)] & __m;
+#else
+      return __OBJ_DATA(__lc_ctype)->mask[static_cast<unsigned
char>(__c)] & __m;
+#endif
   }

   const char*
@@ -57,7 +61,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *__vec++ = _M_table[static_cast<unsigned char>(*__low++)];
     else
       while (__low < __high)
-        *__vec++ = __OBJ_DATA(__lc_ctype)->mask[*__low++];
+#ifdef _THREAD_SAFE
+       *__vec++ =
__OBJ_DATA((*__lc_ctype_ptr))->mask[static_cast<unsigned
char>(*__low++)];
+#else
+        *__vec++ = __OBJ_DATA(__lc_ctype)->mask[static_cast<unsigned
char>(*__low++)];
+#endif
     return __high;
   }


More information about the Libstdc++ mailing list