From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 49E9C2018E for ; Sat, 13 Aug 2016 17:26:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752778AbcHMR0X (ORCPT ); Sat, 13 Aug 2016 13:26:23 -0400 Received: from mout.web.de ([212.227.15.14]:61740 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752762AbcHMR0W (ORCPT ); Sat, 13 Aug 2016 13:26:22 -0400 Received: from [192.168.178.36] ([79.213.114.86]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0LhhVB-1auuHy3RUP-00mrnV; Sat, 13 Aug 2016 19:26:03 +0200 Subject: Re: [PATCH] correct FLEXPTR_* example in comment To: Jeff King References: <57AEE1E1.3080901@web.de> <20160813090947.uj6hurji5o6cwxge@sigill.intra.peff.net> Cc: Git List , Junio C Hamano From: =?UTF-8?Q?Ren=c3=a9_Scharfe?= Message-ID: <57AF582A.3050406@web.de> Date: Sat, 13 Aug 2016 19:26:02 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <20160813090947.uj6hurji5o6cwxge@sigill.intra.peff.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:Wo8f8E+VmB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UqKeQi7e9Bbp2E aMXYfMd Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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. Gcc 5.4 reports "invalid use of flexible array member". > 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. No hint at compile time, segfaults at runtime. > I suppose it could assert(sizeof((x)->flexname) == FLEX_ALLOC) or > something, but I'm not sure if it is worth worrying about. You can't use sizeof with an actual flexible array. It only works if FLEX_ARRAY is defined as 1 (for platforms without native support), and perhaps also if it's 0. offsetof(struct x, arr) == sizeof(struct x) won't work either because of padding. I have no idea what you can do with a flexible array that would throw a compile error when done with a pointer. René