Ignore:
Timestamp:
Jul 20, 2009, 9:02:25 PM (16 years ago)
Author:
[email protected]
Message:

Make it harder to misuse try* allocation routines
https://bugs.webkit.org/show_bug.cgi?id=27469

Reviewed Gavin Barraclough

Jump through a few hoops to make it much harder to accidentally
miss null-checking of values returned by the try-* allocation
routines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/FastMalloc.cpp

    r45566 r46153  
    173173}
    174174   
    175 void* tryFastZeroedMalloc(size_t n)
     175TryMallocReturnValue tryFastZeroedMalloc(size_t n)
    176176{
    177     void* result = tryFastMalloc(n);
    178     if (!result)
     177    void* result;
     178    if (!tryFastMalloc(n).getValue(result))
    179179        return 0;
    180180    memset(result, 0, n);
     
    195195namespace WTF {
    196196
    197 void* tryFastMalloc(size_t n)
     197TryMallocReturnValue tryFastMalloc(size_t n)
    198198{
    199199    ASSERT(!isForbidden());
     
    231231}
    232232
    233 void* tryFastCalloc(size_t n_elements, size_t element_size)
     233TryMallocReturnValue tryFastCalloc(size_t n_elements, size_t element_size)
    234234{
    235235    ASSERT(!isForbidden());
     
    286286}
    287287
    288 void* tryFastRealloc(void* p, size_t n)
     288TryMallocReturnValue tryFastRealloc(void* p, size_t n)
    289289{
    290290    ASSERT(!isForbidden());
     
    33883388}
    33893389
    3390 void* tryFastMalloc(size_t size)
     3390TryMallocReturnValue tryFastMalloc(size_t size)
    33913391{
    33923392    return malloc<false>(size);
     
    34493449}
    34503450
    3451 void* tryFastCalloc(size_t n, size_t elem_size)
     3451TryMallocReturnValue tryFastCalloc(size_t n, size_t elem_size)
    34523452{
    34533453    return calloc<false>(n, elem_size);
     
    35133513}
    35143514
    3515 void* tryFastRealloc(void* old_ptr, size_t new_size)
     3515TryMallocReturnValue tryFastRealloc(void* old_ptr, size_t new_size)
    35163516{
    35173517    return realloc<false>(old_ptr, new_size);
Note: See TracChangeset for help on using the changeset viewer.