Fixed buffer allocation problem for memories bigger than 2GB

 - Updated `chunk_slack` function to return only the result of the
comparison and set `last_chunk_size` via a pointer
 - Updated the other functions which use that function