Author: sebor Date: Sat Sep 6 10:59:18 2008 New Revision: 692697 URL: http://svn.apache.org/viewvc?rev=692697&view=rev Log: 2008-09-06 Martin Sebor <[EMAIL PROTECTED]>
STDCXX-1011 * src/collate.cpp (collate_byname::do_transform): Silenced HP aCC warning #20200: Potential null pointer dereference through return of call to __rw::__rw_get_facet_data(). Optimized the initialization of the facet data so as to take place only in the first iteration of the loop in which it's needed, and not each time. Modified: stdcxx/branches/4.2.x/src/collate.cpp Modified: stdcxx/branches/4.2.x/src/collate.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/src/collate.cpp?rev=692697&r1=692696&r2=692697&view=diff ============================================================================== --- stdcxx/branches/4.2.x/src/collate.cpp (original) +++ stdcxx/branches/4.2.x/src/collate.cpp Sat Sep 6 10:59:18 2008 @@ -966,6 +966,10 @@ // each character, in the process check for collating elements. const char* tmp_lo = low; + // lazily initialized in the first iteration of the loop + // in which the facet data is needed (possibly never) + const _RW::__rw_codecvt_t* cvt = 0; + for (; tmp_lo < high; tmp_lo++) { const char* tmp_lo2 = tmp_lo; int ret = _RW::__rw_get_n_ce_offset (impl, &tmp_lo2, high); @@ -983,18 +987,22 @@ if (impl->undefined_optimization) { size_t size; + if (0 == cvt) { + cvt = _RWSTD_STATIC_CAST (const _RW::__rw_codecvt_t*, + _RW::__rw_get_facet_data ( + ccvt_cat, size, _C_name, + impl->codeset_name ())); - const _RW::__rw_codecvt_t *cvt = - _RWSTD_STATIC_CAST (const _RW::__rw_codecvt_t*, - _RW::__rw_get_facet_data ( - ccvt_cat, size, _C_name, - impl->codeset_name ())); + if (0 == cvt) + return string_type (); // error + } if (_RW::__rw_is_invalid (cvt->n_to_w_tab(), tmp_lo2)) - return 0; + return string_type (); // error - const unsigned int *pwt = + const unsigned int* const pwt = impl->get_weight (impl->undefined_weight_idx); + indexes.append (&pwt, 1); tmp_lo = tmp_lo2; @@ -1194,6 +1202,10 @@ // is high - low _RW::__rw_pod_array<const unsigned int*, 1024> indexes; + // lazily initialized in the first iteration of the loop + // in which the facet data is needed (possibly never) + const _RW::__rw_codecvt_t* cvt = 0; + // first go through the string getting a weight offset for // each character, in the process check for collating elements. for (const wchar_t* tmp_lo =low; tmp_lo < high; tmp_lo++) { @@ -1211,11 +1223,17 @@ // database to discover this information if (impl->undefined_optimization) { size_t size; - const _RW::__rw_codecvt_t *cvt = - _RWSTD_STATIC_CAST (const _RW::__rw_codecvt_t*, - _RW::__rw_get_facet_data ( - ccvt_cat, size, _C_name, - impl->codeset_name ())); + + + if (0 == cvt) { + cvt = _RWSTD_STATIC_CAST(const _RW::__rw_codecvt_t*, + _RW::__rw_get_facet_data ( + ccvt_cat, size, _C_name, + impl->codeset_name ())); + + if (0 == cvt) + return string_type (); // error + } char tmp [_RWSTD_MB_MAX];