public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* libstdc++/6701: do_narrow on range is fubar
@ 2002-05-17 10:16 dale
  0 siblings, 0 replies; 2+ messages in thread
From: dale @ 2002-05-17 10:16 UTC (permalink / raw)
  To: gcc-gnats


>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:


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: libstdc++/6701: do_narrow on range is fubar
@ 2002-05-27  2:33 bkoz
  0 siblings, 0 replies; 2+ messages in thread
From: bkoz @ 2002-05-27  2:33 UTC (permalink / raw)
  To: bkoz, dale, gcc-bugs, gcc-prs, nobody

Synopsis: do_narrow on range is fubar

Responsible-Changed-From-To: unassigned->bkoz
Responsible-Changed-By: bkoz
Responsible-Changed-When: Mon May 27 02:33:05 2002
Responsible-Changed-Why:
    Mine.
State-Changed-From-To: open->closed
State-Changed-By: bkoz
State-Changed-When: Mon May 27 02:33:05 2002
State-Changed-Why:
    Fixed.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6701


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-05-27  9:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-17 10:16 libstdc++/6701: do_narrow on range is fubar dale
2002-05-27  2:33 bkoz

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).