[Live-devel] I found a critical potential error in file MatroskaFileParser.cpp

Ross Finlayson finlayson at live555.com
Thu Dec 12 19:00:20 PST 2013


>> No, this is not a "critical potential error".  It's not even an "error".
>>  It is a compiler *warning* (usually given by some old versions of
>> Microsoft's Visual C++ compiler).
> 
> I don't think VC++ is wholly wrong to warn about this.  The object isn't completely constructed when the initializer list is processed, but 'this' is assumed to point to a constructed object.
> 
> If all the parent ctor does with the value is hold it for use *after* all the ctors run, it's fine.

Yes, and that is what we do.


> If the base ctor dereferences the pointer, though, it's a potential bug.

The only real danger is if the base-class constructor tries to access member fields in the derived class - but the only way that could really happen would be if the base-class constructor were to explicitly cast the pointer into that of the derived class, and then try to dereference it.  Even calling a virtual function wouldn't cause a problem, because (being in a constructor) the base-class function would end up being called instead.

So, IMHO, this (old) compiler is being a bit anal-retentive about issuing a warning here.  In any case, it's not an 'error' at all.


Ross Finlayson
Live Networks, Inc.
http://www.live555.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20131213/7e2854ed/attachment-0001.html>


More information about the live-devel mailing list