Why sizeof(buf) - 1?  OBJ_obj2txt() zero-terminates the buffer, right?  By the way, this should check that the return value >= 0.