buf2hexstr: properly deal with empty string