compute strlen(buf) two times?