You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@stdcxx.apache.org by "Farid Zaripov (JIRA)" <ji...@apache.org> on 2008/05/15 14:23:55 UTC
[jira] Closed: (STDCXX-854) incorrect using the caching array in
ctype::narrow(wchar_t, char)
[ https://issues.apache.org/jira/browse/STDCXX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Farid Zaripov closed STDCXX-854.
--------------------------------
> incorrect using the caching array in ctype<wchar_t>::narrow(wchar_t, char)
> --------------------------------------------------------------------------
>
> Key: STDCXX-854
> URL: https://issues.apache.org/jira/browse/STDCXX-854
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 22. Localization
> Affects Versions: 4.1.2, 4.1.3, 4.1.4, 4.2.0
> Environment: All
> Reporter: Farid Zaripov
> Assignee: Farid Zaripov
> Fix For: 4.2.1
>
> Original Estimate: 1h
> Time Spent: 1h
> Remaining Estimate: 0h
>
> The 22.locale.ctype and 22.locale.ctype.narrow tests are failing with number of assertions. The reason is casting the at least 16-bit wchar_t value to 8-bit unsigned char and using this value as index in cache table in ctype<wchar_t>::narrow(wchar_t, char). As a result the index always fits the table of size 256 elements.
> The proposed patch:
> {noformat}
> Index: include/loc/_ctype.h
> ===================================================================
> --- include/loc/_ctype.h (revision 646660)
> +++ include/loc/_ctype.h (working copy)
> @@ -541,20 +541,21 @@
> inline char
> ctype<wchar_t>::narrow (char_type __c, char __dfault) const
> {
> - const _RWSTD_SIZE_T __inx = _RWSTD_STATIC_CAST (unsigned char, __c);
> -
> // optimize away all but the first call to the virtual do_widen()
> - if ( __inx < sizeof _C_narrow_tab / sizeof *_C_narrow_tab
> - && _C_narrow_tab [__inx])
> - return _C_narrow_tab [__inx];
> + if ( 0 <= __c
> + && __c < sizeof _C_narrow_tab / sizeof *_C_narrow_tab
> + && _C_narrow_tab [__c])
> + return _C_narrow_tab [__c];
>
> // template argument provided to work around an HP aCC bug (PR #27087)
> ctype<wchar_t>* const __self = _RWSTD_CONST_CAST (ctype<wchar_t>*, this);
>
> const char __ch = do_narrow (__c, __dfault);
>
> - if (__inx < sizeof _C_narrow_tab / sizeof *_C_narrow_tab && __ch != __dfault)
> - __self->_C_narrow_tab [__inx] = __ch;
> + if ( 0 <= __c
> + && __c < sizeof _C_narrow_tab / sizeof *_C_narrow_tab
> + && __ch != __dfault)
> + __self->_C_narrow_tab [__c] = __ch;
>
> return __ch;
> }
> {noformat}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.