Send inn-workers mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.isc.org/mailman/listinfo/inn-workers
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of inn-workers digest..."
Today's Topics:
1. Fixing cast-align warning in ovdb (Julien ?LIE)
2. Re: Fixing cast-align warning in ovdb (Russ Allbery)
----------------------------------------------------------------------
Message: 1
Date: Sat, 1 Sep 2018 22:11:33 +0200
From: Julien ?LIE <[email protected]>
To: "[email protected]" <[email protected]>
Subject: Fixing cast-align warning in ovdb
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hi all,
Does anyone have a clue about how to fix the following new warnings emitted by
GCC 8? (without of course generating another different warning)
ovdb/ovdb.c: In function 'ovdb_add':
ovdb/ovdb.c:1951:6: error: cast increases required alignment of target type
[-Werror=cast-align]
((struct ovdata *)databuf)->token = token;
^
ovdb/ovdb.c:1952:6: error: cast increases required alignment of target type
[-Werror=cast-align]
((struct ovdata *)databuf)->arrived = arrived;
^
ovdb/ovdb.c:1953:6: error: cast increases required alignment of target type
[-Werror=cast-align]
((struct ovdata *)databuf)->expires = expires;
^
ovdb_stat.c: In function 'print_value':
ovdb_stat.c:157:7: warning: cast increases required alignment of target type
[-Werror=cast-align]
dl = (DB_LSN *)(cp + tab[i].a);
^
--
Julien ?LIE
??Tuto, cito, iucunde.?? (Esculape)
------------------------------
Message: 2
Date: Sat, 01 Sep 2018 14:45:09 -0700
From: Russ Allbery <[email protected]>
To: [email protected]
Subject: Re: Fixing cast-align warning in ovdb
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Julien ?LIE <[email protected]> writes:
> Does anyone have a clue about how to fix the following new warnings
> emitted by GCC 8? (without of course generating another different
> warning)
> ovdb/ovdb.c: In function 'ovdb_add':
> ovdb/ovdb.c:1951:6: error: cast increases required alignment of target type
> [-Werror=cast-align]
> ((struct ovdata *)databuf)->token = token;
> ^
> ovdb/ovdb.c:1952:6: error: cast increases required alignment of target type
> [-Werror=cast-align]
> ((struct ovdata *)databuf)->arrived = arrived;
> ^
> ovdb/ovdb.c:1953:6: error: cast increases required alignment of target type
> [-Werror=cast-align]
> ((struct ovdata *)databuf)->expires = expires;
> ^
I suspect it will work to change the type of databuf to void *, and then
cast it to (struct ovdata *) when writing into that header and later to
assign it to a variable of type char * when doing pointer math on it. The
pointer is aligned, since the pointer is returned from malloc(), which is
guaranteed to return a pointer with suitable alignment for any built-in
type, so I think the warnings are just because it's immediately assigned
to a char * variable, which has no required alignment, and the compiler
isn't smart enough to keep track of this.
> ovdb_stat.c: In function 'print_value':
> ovdb_stat.c:157:7: warning: cast increases required alignment of target type
> [-Werror=cast-align]
> dl = (DB_LSN *)(cp + tab[i].a);
> ^
This is a similar problem, but the pointer math immediately before use of
the pointer makes it a bit more complicated. If you replace cp in that
expression with (char *) p, I wonder if having all the casts in the same
expression would let the compiler figure it out?
--
Russ Allbery ([email protected]) <http://www.eyrie.org/~eagle/>
Please send questions to the list rather than mailing me directly.
<http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
------------------------------
Subject: Digest Footer
_______________________________________________
inn-workers mailing list
[email protected]
https://lists.isc.org/mailman/listinfo/inn-workers
------------------------------
End of inn-workers Digest, Vol 108, Issue 1
*******************************************