[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ...
From: |
Michael Chang |
Subject: |
Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ... |
Date: |
Wed, 25 Mar 2020 15:27:28 +0800 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Tue, Mar 24, 2020 at 06:54:43PM +0100, Thomas Schmitt wrote:
> 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[]".
I am also investigating the GCC 10 build problems, and my conclusion
mostly coincided with yours. There we can replce the offset computation
with pointer arithmetic like this.
(char *) (sb.dev_roles + grub_le_to_cpu32 (sb.dev_number)) - (char *) &sb,
Besides, there is also build error in zfs that I managed to come up with
a patch as well. I attached both my patch here for your refernce.
It would be great if you can help to test patch to solve the build
problem for gcc-10 in your system or not.
Thanks,
Michael
>
>
> Have a nice day :)
>
> Thomas
>
>
> _______________________________________________
> Grub-devel mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/grub-devel
0001-mdraid1x_linux-Fix-gcc10-error-Werror-array-bounds.patch
Description: Text Data
0002-zfs-Fix-gcc10-error-Werror-zero-length-bounds.patch
Description: Text Data
- grub/head build with pre-release GCC10 ; fail @ "grub-core/disk/mdraid1x_linux.c:181:15: error: ...", PGNet Dev, 2020/03/24
- Re: grub/head build with pre-release GCC10 ; fail @ "grub-core/disk/mdraid1x_linux.c:181:15: error: ...", Paul Menzel, 2020/03/24
- Re: grub/head build with pre-release GCC10 ; fail @ "grub-core/disk/mdraid1x_linux.c:181:15: error: ...", PGNet Dev, 2020/03/24
- Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ..., PGNet Dev, 2020/03/25
- Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ..., Paul Menzel, 2020/03/25
- Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ..., PGNet Dev, 2020/03/25
- Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ..., Paul Menzel, 2020/03/25
- Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ..., Michael Chang, 2020/03/25
- Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ..., PGNet Dev, 2020/03/26
- Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ..., Daniel Kiper, 2020/03/25
- Re: disk/mdraid1x_linux.c:181:15: warning: array subscript ..., Michael Chang, 2020/03/26