I just saw this code:
artist = (char *) malloc(0);
...and I was wondering why would one do this?
malloc(0)
doesn't make any sense to me, unless the code is relying on behaviour specific to the implementation. If the code is meant to be portable, then it has to account for the fact that a NULL return from malloc(0)
isn't a failure. So why not just assign NULL to artist
anyway, since that's a valid successful result, and is less code, and won't cause your maintenance programmers to take time figuring it out?
malloc(SOME_CONSTANT_THAT_MIGHT_BE_ZERO)
or malloc(some_variable_which_might_be_zero)
perhaps could have their uses, although again you have to take extra care not to treat a NULL return as a failure if the value is 0, but a 0 size is supposed to be OK.