public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: dale@peakall.net
To: gcc-gnats@gcc.gnu.org
Subject: libstdc++/6701: do_narrow on range is fubar
Date: Fri, 17 May 2002 10:16:00 -0000	[thread overview]
Message-ID: <20020517171206.988.qmail@sources.redhat.com> (raw)


>Number:         6701
>Category:       libstdc++
>Synopsis:       do_narrow on range is fubar
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 17 10:16:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Dale Peakall
>Release:        gcc 3.1 20020510 (prerelease)
>Organization:
>Environment:
solaris 8
>Description:
The implementation of do_narrow in ctype.cc for a range:
1) always changes the first character to the default char
2) doesn't narrow the whole string if a non-ascii char is
   found

22.2.1.1.2 para 13 of the C++ standard states:

The second form [range form] transforms each character *p
in the range [low, high), placing the result (or dfault if
no simple transformation is readily available) in dest[p-low].
>How-To-Repeat:
std::wstring wide(L"wibble");
std::vector<char> narrow_chars(wide.length() + 1);

std::locale loc;
std::use_facet<std::ctype<wchar_t> >(loc).narrow(
   &wide[0], &wide[wide.length()], '?', &narrow_chars[0]);
>Fix:
  const wchar_t*
  ctype<wchar_t>::
  do_narrow(const wchar_t* __lo, const wchar_t* __hi, char __dfault, 
	    char* __dest) const
  {
    size_t __offset = 0;
    
    for(;;)
    {
      const wchar_t* __start = __lo + __offset;        
      size_t __len = __hi - __start;

      mbstate_t __state;
      memset(static_cast<void*>(&__state), 0, sizeof(mbstate_t));
      size_t __conv = wcsrtombs(__dest + __offset, &__start, __len, &__state);
      if(__conv != __len && __start != 0)
      {
          __offset = __start - __lo;          
          __dest[__offset++] = __dfault;
      }
      else
          break;
    }
      
    return __hi;
  }
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2002-05-17 17:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-17 10:16 dale [this message]
2002-05-27  2:33 bkoz

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=20020517171206.988.qmail@sources.redhat.com \
    --to=dale@peakall.net \
    --cc=gcc-gnats@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).