[PATCH] A few unsorted patches

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Aug 19 13:16:07 MDT 2014

On Tue, Aug 19, 2014 at 12:19:49PM +0200, Volker Lendecke wrote:
> Hi!
> Review would be appreciated!

There's a bug in "locking: Save 48 .text bytes (x86, -O3)" where I don't
know yet exactly what it is.

It seems that the struct initializer does not fill all sizeof(*tmp)
bytes with zero behind "r". If I exchange "r" and "id" in the struct
it works, also if I don't look at sizeof(*tmp) but offsetof(struct
lock_ref_count_key, r)+1. I think that's a subtlety of the struct
initializers together with alignment of complete structs. Essentially
the cast in (uint8_t *)tmp is undefined behaviour.

Adding a *tmp = (struct lock_ref_count_key) {}; also fixes it.

... and I thought those struct initializers are a great idea always :-)

I bet gcc is right. If some language lawyers are listening, I'd love to
read the C99 legalese that explains this.



SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de

More information about the samba-technical mailing list