In first code snippet, you are using(writing) to un-initialized pointer. un-initialized does not mean it's pointing to NULL!
for 2nd case, malloc(0) will return NULL. and of course gets() will...