0

Using YAML::Emitter I sometimes get YAML::Emitter.size() to return a bigger size than strlen(YAML::Emitter.c_str()). e.g.

YAML::Emitter em;
em << something;
if (em.size() > strlen(em.c_str())
{
    std::cout << "WOW " << em.size() << " > " << strlen(em.c_str());
}

This creates issues when writing the yaml text to a buffer:

char* buff = malloc(em.size());
memcpy(buff, em.c_str(), em.size());

because the extra characters at the end fail the yaml parser on the other side that reads this buffer.

Thanks!

Periodic Maintenance
  • 1,698
  • 4
  • 20
  • 32
  • `strlen` will stop at the first null terminator. Do you have any of those? See related https://stackoverflow.com/questions/28028448/strlen-gives-larger-number-than-the-size-of-an-array – Marc Jan 03 '18 at 17:25
  • @Marc No null terminators - I get the full expected yaml as string with em.c_str(). But em.size() returns a bigger size (by 3-8 characters) causing extra characters to be copied. – Periodic Maintenance Jan 03 '18 at 17:29
  • You should probably include a full example that fails, including data being emitted. – Marc Jan 03 '18 at 17:46
  • This might be a bug in yaml-cpp. Could you file an issue on the github page with a complete example? – Jesse Beder Jan 04 '18 at 05:08
  • I noticed that this issue happens when the yaml is relatively large (> 4kbytes). For small buffers, size() matches strlen() exactly. I will try to come up with a reproducible example. – Periodic Maintenance Jan 04 '18 at 08:26

0 Answers0