Check for NULL buffer as well