Ignore:
Timestamp:
Aug 11, 2009, 11:22:41 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 by 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

    r46999 r47092  
    179179}
    180180   
    181 void* tryFastZeroedMalloc(size_t n)
    182 {
    183     void* result = tryFastMalloc(n);
    184     if (!result)
     181TryMallocReturnValue tryFastZeroedMalloc(size_t n)
     182{
     183    void* result;
     184    if (!tryFastMalloc(n).getValue(result))
    185185        return 0;
    186186    memset(result, 0, n);
     
    201201namespace WTF {
    202202
    203 void* tryFastMalloc(size_t n)
     203TryMallocReturnValue tryFastMalloc(size_t n)
    204204{
    205205    ASSERT(!isForbidden());
     
    237237}
    238238
    239 void* tryFastCalloc(size_t n_elements, size_t element_size)
     239TryMallocReturnValue tryFastCalloc(size_t n_elements, size_t element_size)
    240240{
    241241    ASSERT(!isForbidden());
     
    292292}
    293293
    294 void* tryFastRealloc(void* p, size_t n)
     294TryMallocReturnValue tryFastRealloc(void* p, size_t n)
    295295{
    296296    ASSERT(!isForbidden());
     
    35773577}
    35783578
    3579 void* tryFastMalloc(size_t size)
     3579TryMallocReturnValue tryFastMalloc(size_t size)
    35803580{
    35813581    return malloc<false>(size);
     
    36383638}
    36393639
    3640 void* tryFastCalloc(size_t n, size_t elem_size)
     3640TryMallocReturnValue tryFastCalloc(size_t n, size_t elem_size)
    36413641{
    36423642    return calloc<false>(n, elem_size);
     
    37023702}
    37033703
    3704 void* tryFastRealloc(void* old_ptr, size_t new_size)
     3704TryMallocReturnValue tryFastRealloc(void* old_ptr, size_t new_size)
    37053705{
    37063706    return realloc<false>(old_ptr, new_size);
Note: See TracChangeset for help on using the changeset viewer.