All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Schmitt" <scdbackup@gmx.net>
To: grub-devel@gnu.org
Cc: pmenzel@molgen.mpg.de
Subject: Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ...
Date: Tue, 24 Mar 2020 18:54:43 +0100	[thread overview]
Message-ID: <9634719282783168194@scdbackup.webframe.org> (raw)
In-Reply-To: <c9220057-3f5d-ae09-6c86-7d5c17356e86@gmail.com>

Hi,

i wrote:
> >                (char *) &sb.dev_roles - (char *) sb
> >                + grub_le_to_cpu32 (sb.dev_number) * sizeof(grub_uint16_t)

PGNet Dev wrote:
> grub-core/disk/mdraid1x_linux.c:183:6: error: cannot convert to a
> pointer type

My fault. I forgot the "&" before "sb".

  (char *) &sb.dev_roles - (char *) &sb

I invested time in examining the C riddle, not in testing my proposal
by at least some dummy.

Now this compiles for me without complaint by gcc -Wall

 struct {
   char a_array[10];
   uint16_t dev_roles[0];
 } sb;

 printf("%u\n", (unsigned int) (((char *) &sb.dev_roles - (char *) &sb)
                                + 2 * sizeof(uint16_t)));

Running this program yields 14 as result. The same as with the equivalent
of the old expression

 printf("%u\n", (unsigned int) ((char *) &sb.dev_roles[2] - (char *) &sb));


> not sure I'm reading your intent from your post,

My observation is that not "dev_roles[0]" is to blame for the warning, but
rather the computation which involves taking the address of an array
element while not a single one is allocated.
The resulting number is used as offset in a file, not in the sparsely
allocated "struct grub_raid_super_1x sb".

My proposal is to avoid "[...]" in the course of the computation.
This should be valid for both ways to express an open ended struct:
"dev_roles[0]" and "dev_roles[]".


Have a nice day :)

Thomas



  parent reply	other threads:[~2020-03-24 17:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24  4:00 grub/head build with pre-release GCC10 ; fail @ "grub-core/disk/mdraid1x_linux.c:181:15: error: ..." PGNet Dev
2020-03-24 14:51 ` Paul Menzel
2020-03-24 16:52   ` PGNet Dev
2020-03-24 17:04     ` PGNet Dev
2020-03-24 17:54     ` Thomas Schmitt [this message]
2020-03-25  7:27       ` disk/mdraid1x_linux.c:181:15: warning: array subscript Michael Chang
2020-03-25 11:13         ` Thomas Schmitt
2020-03-26  3:08           ` Michael Chang
2020-03-25 15:35         ` PGNet Dev
2020-03-25 15:52           ` Paul Menzel
2020-03-25 15:54             ` PGNet Dev
2020-03-25 16:08               ` Paul Menzel
2020-03-26  3:29           ` Michael Chang
2020-03-26  4:05             ` PGNet Dev
2020-03-25 18:35         ` Daniel Kiper
2020-03-26  4:13           ` Michael Chang
2020-03-26  4:24             ` Michael Chang
  -- strict thread matches above, loose matches on Subject: below --
2020-03-20  8:24 disk/mdraid1x_linux.c:181:15: warning: array subscript <unknown> is outside array bounds of ‘grub_uint16_t[0]’ {aka ‘short unsigned int[0]’} [-Warray-bounds] Paul Menzel
2020-03-20 13:05 ` disk/mdraid1x_linux.c:181:15: warning: array subscript Thomas Schmitt

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9634719282783168194@scdbackup.webframe.org \
    --to=scdbackup@gmx.net \
    --cc=grub-devel@gnu.org \
    --cc=pmenzel@molgen.mpg.de \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.