BUF_MEM->length is an int, not size_t