How to be more careful about null pointers?

cy via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 28 14:06:52 PDT 2016


On Monday, 28 March 2016 at 21:01:19 UTC, cy wrote:
> I invoked db.find_chapter.bindAll(8,4), when db was a null 
> pointer.

No, no, no it's worse than that. What I did was (db.)find_chapter 
= (db.)backend.prepare("...") when backend was null, and got no 
error. find_chapter was garbage of course, but there was no 
error. And only much later, when I called 
db.find_chapter.bindAll(...) did it react to the garbage data, by 
messily segfaulting. db was a good pointer, but db.backend was 
bad, and db.backend.prepare() didn't even flinch getting passed a 
null this, and dereferencing that null internally to construct 
Statement(Database,string).


More information about the Digitalmars-d-learn mailing list