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
Style issues here. Use end_chunk and the GNU style in this file (or if it fails to follow it, try to mimic it).