components/stdcxx/patches/086-tmpbuf.cpp.patch
changeset 402 94ae4d75524c
equal deleted inserted replaced
401:bf52ef48020c 402:94ae4d75524c
       
     1 --- stdcxx-4.2.1/src/tmpbuf.cpp	2008-04-24 17:25:19.000000000 -0700
       
     2 +++ stdcxx-4.2.1/src/tmpbuf.cpp	2011-03-22 15:16:51.692183430 -0700
       
     3 @@ -40,31 +40,28 @@
       
     4  typedef char _CharBuf [_RWSTD_TMPBUF_SIZE + !_RWSTD_TMPBUF_SIZE];
       
     5  
       
     6  // use `aligned_buffer' to guarantee proper buffer alignment
       
     7 -static _RWSTD_THREAD __rw_aligned_buffer<_CharBuf>
       
     8 -__rw_buffer;
       
     9 -
       
    10 -static _RWSTD_THREAD unsigned long
       
    11 -__rw_buffer_busy /* = 0 */;   // > 0 when buffer in use
       
    12 +static _RWSTD_THREAD __rw_aligned_buffer<_CharBuf> __rw_buffer;
       
    13  
       
    14 +// > 0 when buffer in use
       
    15 +static _RWSTD_THREAD unsigned long __rw_buffer_busy = 0UL;
       
    16  
       
    17  // extern "C" to avoid binary incompatibility due to changes
       
    18  // in function arguments (e.g., their sign)
       
    19  extern "C" {
       
    20  
       
    21 -
       
    22  // used by std::get_temporary_buffer<>()
       
    23  _RWSTD_EXPORT _RWSTD_SIZE_T
       
    24  __rw_tmpbuf (void **pptr, _RWSTD_PTRDIFF_T nelems, _RWSTD_SIZE_T size)
       
    25  {
       
    26 -    _RWSTD_ASSERT (0 != pptr);
       
    27 -    _RWSTD_ASSERT (0 != size);
       
    28 +    if ((0UL == pptr) || (0 == size))
       
    29 +	return 0;
       
    30  
       
    31      // detect overflow and fail
       
    32      _RWSTD_SIZE_T nbytes = nelems * size;
       
    33  
       
    34 -    if (   nelems < 0
       
    35 -        || nbytes / size != _RWSTD_STATIC_CAST (_RWSTD_SIZE_T, nelems)
       
    36 -        || nelems && nbytes / nelems != size) {
       
    37 +    if (   (nelems < 0)
       
    38 +        || ((nbytes / size) != _RWSTD_STATIC_CAST (_RWSTD_SIZE_T, nelems))
       
    39 +        || ((nelems > 0) && ((nbytes / nelems) != size))) {
       
    40          *pptr = 0;
       
    41          return 0;
       
    42      }