Check for asprintf errors correctly

asprintf returns the number of bytes allocated, and -1 for error.