C-coders of HN, do you use plain vanilla C strings in your project (s)? I was under the impression that most (at least bigger ones) use some custom length carrying string type to avoid exactly these sort of problems
Simple to implement and use (and also backwards compatible), provided you have a library of common functions for allocating, copying, etc.
If I'm size constrained, I'll consider uint16_t for the length field. If I'm REALLY size constrained, I'll use a VLQ [1] for the length field and take the slight performance hit.
[1] https://github.com/kstenerud/vlq/blob/master/vlq-specificati...
When I do apps I have my own length-prefixed variant.