pantoniou / libfyaml

Fully feature complete YAML parser and emitter, supporting the latest YAML spec and passing the full YAML testsuite.
MIT License
241 stars 74 forks source link

build_from/emit_to string reverse operation, result not the same as origin, maybe memory breaked #23

Closed leongle closed 1 year ago

leongle commented 4 years ago

build_from_file, emit to string, build_from_string again , then emit to file, the file not the same as origin

    fyd = fy_document_build_from_file(NULL, "key.yaml");
    char *out = NULL, *in = NULL;    
   out = fy_emit_document_to_string(fyd, FYECF_DEFAULT);
    if (out) {
        printf("out[\n%s\n] line[%d]\n", out, __LINE__);
    }
       fy_document_destroy(fyd); fyd=NULL;
    in = out;
    printf("in[\n%s\n] len[%ld] line[%d]\n", in, strlen(in), __LINE__);
    fyd = fy_document_build_from_string(NULL, in, FY_NT); // BUG,乱码
    //fyd = fy_document_create(NULL);
    //fyn = fy_node_build_from_string(fyd, in, strlen(in)); // BUG, 乱码
    free(out); out=NULL;
    fy_emit_document_to_file(fyd, FYECF_DEFAULT, "key.yaml.tmp2");