first check that buf is not NULL. then use memset to set the data to 0 if required.