That's true, although there's no reason the stack allocator couldn't record this information somewhere as well.
And if the memory allocator doesn't know about the string then you could just revert to the existing behaviour so you're no worse off.
And if the memory allocator doesn't know about the string then you could just revert to the existing behaviour so you're no worse off.
static char buf[128];
and use strcpy() at any point to copy into it, so I don't think statically allocated strings must be literals.The point is not that allocators don't know how much memory has been allocated, but that C has no idea about the underlying allocator, so it cannot ask it about the length of the string as it was proposed.
How much C code is out there that only uses malloc/free? All of those programs could be made safer if the default string methods were able to prevent writing past the end of the array.