Fixed bug allocating negative size buffer