Walter Bright wrote:
Brad Roberts wrote:
Walter Bright wrote:
strlen() is safe, while strcpy() and printf() are not.
You sure? Does running beyond the bounds of the array if there's no null
termination count as safe some how? :)
Yes. Memory safety is defined as being free of memory corruption errors.
Simply reading memory out of bounds does not corrupt memory.
It does result in undefined behaviour, though. I don't see much
difference. (Corrupting memory is a problem only because you read it
again afterwards...)
Note that it is ok for a memory safe program to generate a seg fault.
It'd be OK if it was guaranteed to generate a seg fault. But I don't
think that's true here.
printf() is not memory safe because of the %n format.