ensure buf is defined before usage