public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: David Edelsohn <dje@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r11-6826] aix: make ctype_inline.h thread-safe and avoid _OBJ_DATA char subscript.
Date: Wed, 20 Jan 2021 23:04:57 +0000 (GMT)	[thread overview]
Message-ID: <20210120230457.C33723971822@sourceware.org> (raw)

https://gcc.gnu.org/g:fb39c4fe445beab2e2bf9402a8ccb3c541f2aa5c

commit r11-6826-gfb39c4fe445beab2e2bf9402a8ccb3c541f2aa5c
Author: David Edelsohn <dje.gcc@gmail.com>
Date:   Tue Jan 19 22:24:08 2021 -0500

    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.
    
    libstdc++-v3/ChangeLog:
    
            * 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:
---
 libstdc++-v3/config/os/aix/ctype_inline.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

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;
   }


                 reply	other threads:[~2021-01-20 23:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210120230457.C33723971822@sourceware.org \
    --to=dje@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).