Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usage of mbuf_printf #117

Closed
lxlenovostar opened this issue Mar 15, 2018 · 2 comments
Closed

usage of mbuf_printf #117

lxlenovostar opened this issue Mar 15, 2018 · 2 comments

Comments

@lxlenovostar
Copy link

I use mbuf_printf in this way:

  {    
       struct odict* result_dict;
       struct mbuf* mb_ref = NULL;
       int64_t result = 0; 
       mb_ref = mbuf_alloc(1024);
       if (!mb_ref) {
           DEBUG_WARNING("ENOMEM.\n");
       }    

       char *flvname = "512aaaa";
       EOR(odict_alloc(&result_dict, 16));
       EOR(odict_entry_add(result_dict, "name", ODICT_STRING, flvname));

       mbuf_printf(mb_ref, "%H", json_encode_odict, result_dict);

       char buf[1024];
       re_snprintf(buf, sizeof(buf), "%H", json_encode_odict, result_dict);

       DEBUG_WARNING("mbuf:%s\nbuf:%s\n", mbuf_buf(mb_ref), buf);   
   }  

I run it on ubuntu(x86_64), the result is:
_031518_063903_pm

buf has the right value, the mb_ref don't have the right value. I have check mbuf_printf example in reTest.
This is why? Thank you.

@alfredh
Copy link
Contributor

alfredh commented Mar 16, 2018

mbuf buf is a binary buffer , it is not null terminated and you can not use %s to print it

You can for example use %b instead:

re_printf("mbuf: %b\n", mb->buf, mb->end);

Alfred

@lxlenovostar
Copy link
Author

@alfredh Thank you. I fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants