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. Re: Fixing cast-align warning in ovdb (Julien ?LIE)


----------------------------------------------------------------------

Message: 1
Date: Sun, 2 Sep 2018 22:10:07 +0200
From: Julien ?LIE <[email protected]>
To: [email protected]
Subject: Re: Fixing cast-align warning in ovdb
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed

Hi Russ,

>> 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.

-    ((struct ovdata *)databuf)->token = token;
-    ((struct ovdata *)databuf)->arrived = arrived;
-    ((struct ovdata *)databuf)->expires = expires;
+    ((struct ovdata *)(void *)databuf)->token = token;
+    ((struct ovdata *)(void *)databuf)->arrived = arrived;
+    ((struct ovdata *)(void *)databuf)->expires = expires;

gcc indeed no longer complains with the above change.



> 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.

OK, thanks!



>> 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?

Still the same cast-align error with either
   dl = (DB_LSN *)((char *)cp + tab[i].a);
or
   dl = (DB_LSN *)((char *)p + tab[i].a);

Note that
   dl = (DB_LSN *)(void *)(cp + tab[i].a);
suppresses the warning.  I can commit that change too so that the 
warning is suppressed.

-- 
Julien ?LIE

??Vti, non abuti.??


------------------------------

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 2
*******************************************

Reply via email to