static int collect(BUF_MEM **collector, void *data, size_t datalen)
{
    size_t i;

    if (*collector == NULL)
        *collector = BUF_MEM_new();
    if (*collector == NULL) {
        ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
        return 0;
    }

    i = (*collector)->length; /* BUF_MEM_grow() changes it! */
    /*
     * The i + datalen check is to distinguish between BUF_MEM_grow()
     * signaling an error and BUF_MEM_grow() simply returning the (zero)
     * length.
     */
    if (!BUF_MEM_grow(*collector, i + datalen)
        && i + datalen != 0)
        return 0;
    if (data != NULL)
        memcpy((*collector)->data + i, data, datalen);
    return 1;
}