From: "René Scharfe" <l.s.r@web.de>
To: Jeff King <peff@peff.net>
Cc: Git List <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] correct FLEXPTR_* example in comment
Date: Sat, 13 Aug 2016 19:26:02 +0200 [thread overview]
Message-ID: <57AF582A.3050406@web.de> (raw)
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.
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é
next prev parent reply other threads:[~2016-08-13 17:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-13 9:01 [PATCH] correct FLEXPTR_* example in comment René Scharfe
2016-08-13 9:09 ` Jeff King
2016-08-13 9:19 ` René Scharfe
2016-08-13 17:26 ` René Scharfe [this message]
2016-08-13 18:36 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=57AF582A.3050406@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).