err.h: add helper function to simplify pointer error checking