Use the (un)marshalling functions scsi_get/set_uint16/32() anywhere in the code
This has the nice side effect to remove the compiler warning "dereferencing type-punned pointer will break strict-aliasing rules" which occur since gcc-4.7. There are 79 locations where the warning occurs. All of them are in statements where the htonl/htons/ntohl/ntohs functions are used, e.g.: in lib/pdu.c itt = ntohl(*(uint32_t *)&in->hdr[16]); in lib/scsi-lowlevel.c *(uint32_t *)&task->cdb[2] = htonl(lba); The warning is not related to the htonl/htons/ntohl/ntohs functions but to the casting/dereferencing operation. If the dereferenced variable is already a pointer, the warning does not not occur, e.g. this one: in lib/pdu.c itt = ntohl(*(uint32_t *)&in->data[16]); The warning is caused by the -fstrict-aliasing option. The -fstrict-aliasing option is enabled at optimization levels -O2, -O3, -Os. Signed-off-by: Bernhard Kohl <bernhard.kohl@gmx.net>
This commit is contained in:
committed by
Ronnie Sahlberg
parent
7e4b33dd31
commit
6644389907
+1
-1
@@ -87,7 +87,7 @@ iscsi_process_task_mgmt_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
|
||||
|
||||
response = in->hdr[2];
|
||||
|
||||
maxcmdsn = ntohl(*(uint32_t *)&in->hdr[32]);
|
||||
maxcmdsn = scsi_get_uint32(&in->hdr[32]);
|
||||
if (maxcmdsn > iscsi->maxcmdsn) {
|
||||
iscsi->maxcmdsn = maxcmdsn;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user