Gisle Aas <gisle@ActiveState.com> writes: > The following invariant should always hold if SvPOK(sv): > > - SvCUR(sv) < SvLEN(sv) > - *SvEND(sv) == '\0' > > The perl core ensures that and so should extensions. The perlguts > manpage says: > > All SVs that contain strings should be terminated with a > NUL character. If it is not NUL-terminated there is a > risk of core dumps and corruptions from code which passes > the string to C functions or system calls which expect a > NUL-terminated string. I just wanted to follow up on this with one more point. It's not only for external APIs this is important. You will also find code that does things like this: char *s = SvPVX(sv); //... while (isDIGIT(*s)) s++; This is unsafe unless the invariant described above holds. The perl core is full of similar cases and I know I've depended on this a lot in the HTML::Parser module and other places. --GisleThread Previous