-
Notifications
You must be signed in to change notification settings - Fork 130
Open
Description
The following minimal example produces a malformed YAML file - if I understand correctly, unprintable characters are forbidden from being emitted into the YAML file, but this example produces key names with embedded \0's:
ryml::Tree newTree;
ryml::NodeRef root = newTree.rootref();
root |= ryml::MAP;
char entryName[32] = "EntryName";
// Sanitize 'entryName' here...
c4::csubstr key = c4::to_csubstr(entryName);
root[key] << 1;
FILE* file = fopen("test.yml", "w");
if (file != nullptr)
{
ryml::emit_yaml(newTree, file);
fclose(file);
}The issue seems to be related to the fact that the following overload of to_csubstr is used:
template<size_t N>
C4_ALWAYS_INLINE csubstr
to_csubstr(const char (&s)[N]) noexcept { csubstr ss(s, N-1); return ss; }This overload determines the buffer length at compile time and should be reserved ONLY to string literals, and arrays should always be directed to a const char* overload that determines the string length on runtime. This is evident if I inspect the value of key in the debugger:

To verify, I removed the const char (&s)[N] overload locally, and that "fixes" this specific case.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels