4 ms·
It may be syntactically terse but I'm not sure it's elegant as you would need to do several checks before this line or else you could end up with some pretty ma
by justncase80 11y ago
It may be syntactically terse but I'm not sure it's elegant as you would need to do several checks before this line or else you could end up with some pretty major bugs.
For example, you would need to ensure that sizeof p is >= sizeof q, or else you will end up with a buffer overflow. This then implies that q has a length and therefore a \0. So you will need to iterate through the string once to find the \0 (which may not be there).
Failure to do this can lead to execution of arbitrary code, which is why null terminated strings are indefensible frankly.
- camperman 11y agoI read (and used) this during a more civilized age when everyone and his dog wasn't trying to get your program to execute arbitrary code, although I have still used the construct on a recent project on the Raspberry Pi and it worked just fine.
- justncase80 11y agoYou're very naughty ;)