[Spice-devel] [PATCH 07/17] Get rid of C-style memset initializations, use C++ style aggregates

Christophe Fergeau cfergeau at redhat.com
Fri Feb 23 11:08:55 UTC 2018


On Fri, Feb 23, 2018 at 12:01:59PM +0100, Christophe de Dinechin wrote:
> 
> 
> > On 23 Feb 2018, at 10:53, Christophe Fergeau <cfergeau at redhat.com> wrote:
> > 
> > Given the lengthy debate over what is mostly a small cosmetic patch, I
> > suggest that we postpone this one for now and drop it from the series.
> 
> memset in C++ code is not just a style issue, it’s dangerous. It completely wipes out C++ type guarantees. For example, if someone inits a field with
> 
> 	int x = 1;
> 
> Then all constructors will guarantee that x == -1, but a memset after
> object creation wipes out that guarantee. Same thing if we make of of
> the objects being memset-initialized contain some C++ object with a
> vtable. And so on. All these problems do not exist with C++
> zero-initialization.

Is this an actual problem with the 2 structs which are being discussed
here? In other word, is this patch currently fixing a bug? I don't think
it does, so it can safely be postponed for a later time when people get
to an agreement on it, or when we have less patches pending, ...

> Which is also significantly shorter to write.

I did not mention it the first time, but this patch is added more lines
that it removes. So I'll beg to disagree with the "shorter" part ;)

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180223/ce0ad6d5/attachment.sig>


More information about the Spice-devel mailing list