Either use new char[] or check that buf != NULL.