From: René Scharfe Date: Sat, 13 Aug 2016 09:19:22 GMT Subject: Re: [PATCH] correct FLEXPTR_* example in comment Message-ID: <57AEE61A.4000804@web.de> In-Reply-To: <20160813090947.uj6hurji5o6cwxge@sigill.intra.peff.net> Am 13.08.2016 um 11:09 schrieb Jeff King: > On Sat, Aug 13, 2016 at 11:01:21AM +0200, René Scharfe wrote: > >> This section is about "The FLEXPTR_* variants", so use FLEXPTR_ALLOC_STR >> in the example. > > Oops, yeah. Your patch is clearly an improvement. > > Since this is obviously an easy mistake to make (using one form rather > than the other), I wondered if the compiler would catch it. > > I think it would catch an accidental use of FLEXPTR instead of FLEX, > because it involves an attempted assignment of an array. But I don't > think we would catch the reverse; we'd just write the data directly on > top of the pointer. That would probably crash immediately at runtime, so > if you exercise the code at all in tests, it is OK. But something to be > aware of. > > I suppose it could assert(sizeof((x)->flexname) == FLEX_ALLOC) or > something, but I'm not sure if it is worth worrying about. A compilation error or warning would be nice. I scratched my head quite a bit before figuring out that the example was wrong. Copy&paste from a reputable source must be correct, right? :) René