O'Reilly logo
  • Alain O'Dea thinks this is interesting:

(char *) malloc(200)


Cover of Hacking: The Art of Exploitation, 2nd Edition


Should be "malloc(sizeof(char)*200)". The return value of malloc should not be cast as it can mask a missing include of stdlib.h. It's a best practice to use the sizeof multiplier as malloc takes a number of bytes to allocate and not the number of elements of the target type (which it can't possibly know).