Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXblu-0003mK-Uh for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:43:02 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXblq-0003hD-61 for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:43:02 -0500 Received: from [199.232.76.173] (port=33499 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXblp-0003gu-Rc for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:42:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50012) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXblp-00016o-30 for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:42:57 -0500 From: Markus Armbruster Subject: Re: [Qemu-devel] Re: [PATCH 07/17] block/vvfat.c: fix warnings with _FORTIFY_SOURCE References: <85e877202ec86dac15d392f5e88d5b5d76e3b02f.1263944807.git.quintela@redhat.com> <20100120103324.GA17856@redhat.com> <4B56ECBC.40804@redhat.com> Date: Wed, 20 Jan 2010 15:42:53 +0100 In-Reply-To: (Kirill A. Shutemov's message of "Wed, 20 Jan 2010 15:51:14 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Kirill A. Shutemov" Cc: Kevin Wolf , qemu-devel@nongnu.org, Juan Quintela [Some quoted material restored] "Kirill A. Shutemov" writes: > On Wed, Jan 20, 2010 at 3:03 PM, Markus Armbruster wrote: >> "Kirill A. Shutemov" writes: >>> On Wed, Jan 20, 2010 at 2:15 PM, Markus Armbruster wrote: >>>> Kevin Wolf writes: >>>>> Regardless if deliberately overflowing the buffer works or doesn't >>>>> making it explicit is better. Someone might reorder the struct or add >>>>> new fields in between (okay, unlikely in this case, but still) and >>>>> you'll overflow into fields you never wanted to touch. >>>> >>>> Moreover, compilers are free to put padding between members name and >>>> extension. >>> >>> No, compiler can't add anything between. 'char' is always byte-aligned. >> >> You got some reading to do then. > > Do you want to say that it's not true? Could you provide an example > when 'char' isn't byte-aligned? I was wrong, because I overlooked __attribute__((packed)). ISO/IEC 9899:1999 6.7.2.1 guarantees a number of things for structs, chiefly members stay in order, no padding before the first member. But it does not restrict padding between members or at the end in any way, so compilers may pad there how they see fit. In particular, there is no rule that a compiler may only add padding to satisfy the next member's alignment requirement. __attribute__((packed)) tightens the spec to eliminate padding. Regardless, the deliberate buffer overflow to hopefully save a few bytes and cycles is a dirty, brittle trick for no good reason. If this really must be hand-optimized (numbers, please), do it cleanly, the way Dan suggested.