Date: Tue, 28 Aug 2012 12:57:45 +0400 From: Andrey Zonov <zont@FreeBSD.org> To: freebsd-arch@freebsd.org Subject: warning: cast increases required alignment of target type Message-ID: <503C8809.3050507@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig0788A89F08941CC5D4233F50
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi,
Does anyone know how to correctly fix this warning for
arm/ia64/mips/sparc64?
usr.bin/elf2aout/elf2aout.c: In function 'main':
usr.bin/elf2aout/elf2aout.c:129: warning: cast increases required
alignment of target type
I found this explanation from bde, but still don't understand how to
correctly fix this issue.
------------------------------------------------------------------------
r99799 | bde | 2002-07-11 22:06:09 +0400 (Thu, 11 Jul 2002) | 10 lines
Set NO_WERROR to ignore the following warning which is emitted on
alphas:
.../elf2aout.c:130: warning: cast increases required alignment of
target type
The warning is about casting ((char *)e + phoff) to a struct pointer,
where e is aligned but phoff might be garbage, so I think the warning
should be emitted on most machines (even on i386's, alignment checking
might be on) and the correct fix would involve validation phoff before
using it.
Is this fix correct?
Index: usr.bin/elf2aout/elf2aout.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- usr.bin/elf2aout/elf2aout.c (revision 239611)
+++ usr.bin/elf2aout/elf2aout.c (working copy)
@@ -126,7 +126,7 @@
entry =3D xe64toh(e->e_entry);
phoff =3D xe64toh(e->e_phoff);
phnum =3D xe16toh(e->e_phnum);
- p =3D (Elf64_Phdr *)((char *)e + phoff);
+ p =3D (Elf64_Phdr *)(void *)((char *)e + phoff);
bzero(&a, sizeof(a));
for (i =3D 0; i < phnum; i++) {
type =3D xe32toh(p[i].p_type);
--=20
Andrey Zonov
--------------enig0788A89F08941CC5D4233F50
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
Comment: GPGTools - http://gpgtools.org
iQEcBAEBAgAGBQJQPIgNAAoJEBWLemxX/CvT84YH/ifd1jhi4TimbVr6Ze9roCeF
Jy5iZu0mY+0aW6w1guUSrJPE1K5DTqlRlgpWIhRcRogEyCfM6Ami8E4+aCts2OWT
BlEXJeHasvzWLuC64KtDLNtl0GLIlFNSk18wxWmRkI1QsfAOy1x94XPcladB9JDV
E07lpKJWlFEZfUmSCVSI6/Ui4R0RqHzHh86CaxziOnBgHqKt0s0TJD/UaM0IRf93
T/OzBdp6n/Pivt72CRu45/sbCDrhtGn4yTLTQ4KOjbDTOwBAPoOOyYCgdTk/k+Pe
ScGvDubxVWKQJkQToPMB05LWZ206i2Z96L3z253YIIES8dE9rhE3VGARmZPok60=
=pGE6
-----END PGP SIGNATURE-----
--------------enig0788A89F08941CC5D4233F50--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?503C8809.3050507>
