Return NULL rather than an invalid pointer on failure