Comment 11 for bug 907761

Revision history for this message
Andrew Johnson (anj) wrote :

strncpy() is regarded as a major source of bugs and security problems in C code when a programmer forgets to force the terminating zero byte; I want to avoid repeating that mistake. In all the cases we're talking about we know that the data we are looking at is a character string and not just an array of bytes, so we can remove a possible source of bugs in client code by nil-terminating the result. This isn't "faking" anything, it's trying to maintain the invariant that C strings are (supposed to be) nil-terminated.

I fully admit that long strings were a string-and-sealing-wax addition to Base, but that's no reason not to file off any unnecessary sharp edges so our users don't get hurt unnecessarily.

I'm attaching a patch which allows single-element fetches, fixes the double subtraction issues, and adds nil-termination to DBF_STRING fields being read as long-string char arrays. If you can try it out I would appreciate another set of eyes on the result before I commit it and add it to the Known Problems page.

Thanks,

- Andrew