third_party/cairo/src/cairo-os2-surface.c
void *_buffer_alloc (size_t a, size_t b, const unsigned int size)
{
    size_t nbytes;
    void  *buffer = NULL;

    if (!a || !b || !size ||
        a >= INT32_MAX / b || a*b >= INT32_MAX / size) {
        return NULL;
    }
    nbytes = a * b * size;

#ifdef OS2_USE_PLATFORM_ALLOC
    /* Using OBJ_ANY on a machine that isn't configured for hi-mem
     * will cause ERROR_INVALID_PARAMETER.  If this occurs, or this
     * build doesn't have hi-mem enabled, fall back to using lo-mem.
     */
#ifdef OS2_HIGH_MEMORY
    if (!DosAllocMem (&buffer, nbytes,
                      OBJ_ANY | PAG_READ | PAG_WRITE | PAG_COMMIT))
        return buffer;
#endif
    if (DosAllocMem (&buffer, nbytes,
                     PAG_READ | PAG_WRITE | PAG_COMMIT))
        return NULL;
#else
    /* Clear the malloc'd buffer the way DosAllocMem() does. */
    buffer = _cairo_malloc (nbytes);
    if (buffer) {
        memset (buffer, 0, nbytes);
    }
#endif
    return buffer;
}
/*
 * This function calls the allocation function depending on which
 * method was compiled into the library: it can be native allocation
 * (DosAllocMem/DosFreeMem) or C-Library based allocation (malloc/free).
 * Actually, for pixel buffers that we use this function for, cairo
 * uses _cairo_malloc_abc, so we use that here, too. And use the
 * change to check the size argument
 */
This function calls the allocation function depending on which
method was compiled into the library: it can be native allocation
(DosAllocMem/DosFreeMem) or C-Library based allocation (malloc/free).
Actually, for pixel buffers that we use this function for, cairo
uses _cairo_malloc_abc, so we use that here, too. And use the
change to check the size argument
This function calls the allocation function depending on which method was compiled into the library : it can be native allocation ( DosAllocMem / DosFreeMem ) or C - Library based allocation ( malloc / free ) . Actually for pixel buffers that we use this function for cairo uses _cairo_malloc_abc so we use that here too . And use the change to check the size argument
void *_buffer_alloc (size_t a, size_t b, const unsigned int size)
{
    size_t nbytes;
    void  *buffer = NULL;
    if (!a || !b || !size ||
        a >= INT32_MAX / b || a*b >= INT32_MAX / size) {
        return NULL;
    }
    nbytes = a * b * size;
#ifdef OS2_USE_PLATFORM_ALLOC
#ifdef OS2_HIGH_MEMORY
    if (!DosAllocMem (&buffer, nbytes,
                      OBJ_ANY | PAG_READ | PAG_WRITE | PAG_COMMIT))
        return buffer;
#endif
    if (DosAllocMem (&buffer, nbytes,
                     PAG_READ | PAG_WRITE | PAG_COMMIT))
        return NULL;
#else
    buffer = _cairo_malloc (nbytes);
    if (buffer) {
        memset (buffer, 0, nbytes);
    }
#endif
    return buffer;
}
void * _buffer_alloc ( size_t a , size_t b , const unsigned int size ) { size_t nbytes ; void * buffer = NULL ; if ( ! a || ! b || ! size || a >= INT32_MAX / b || a * b >= INT32_MAX / size ) { return NULL ; } nbytes = a * b * size ; #ifdef OS2_USE_PLATFORM_ALLOC #ifdef OS2_HIGH_MEMORY if ( ! DosAllocMem ( & buffer , nbytes , OBJ_ANY | PAG_READ | PAG_WRITE | PAG_COMMIT ) ) return buffer ; #endif if ( DosAllocMem ( & buffer , nbytes , PAG_READ | PAG_WRITE | PAG_COMMIT ) ) return NULL ; #else buffer = _cairo_malloc ( nbytes ) ; if ( buffer ) { memset ( buffer , 0 , nbytes ) ; } #endif return buffer ; }
This function calls the allocation function depending on which
 method was compiled into the library: it can be native allocation
 (DosAllocMem/DosFreeMem) or C-Library based allocation (malloc/free).
This function calls the allocation function depending on which method was compiled into the library : it can be native allocation ( DosAllocMem / DosFreeMem ) or C - Library based allocation ( malloc / free ) .
/* Using OBJ_ANY on a machine that isn't configured for hi-mem
     * will cause ERROR_INVALID_PARAMETER.  If this occurs, or this
     * build doesn't have hi-mem enabled, fall back to using lo-mem.
     */ /* Clear the malloc'd buffer the way DosAllocMem() does. */