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:
Bernhard Kohl
2012-11-23 23:14:09 +01:00
committed by Ronnie Sahlberg
parent 7e4b33dd31
commit 6644389907
5 changed files with 148 additions and 148 deletions

View File

@@ -30,6 +30,7 @@
#include <string.h>
#include "iscsi.h"
#include "iscsi-private.h"
#include "scsi-lowlevel.h"
#include "md5.h"
static int
@@ -944,11 +945,11 @@ iscsi_process_login_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
char *ptr = (char *)in->data;
int size = in->data_pos;
status = ntohs(*(uint16_t *)&in->hdr[36]);
status = scsi_get_uint16(&in->hdr[36]);
iscsi->statsn = ntohs(*(uint16_t *)&in->hdr[24]);
iscsi->statsn = scsi_get_uint16(&in->hdr[24]);
maxcmdsn = ntohl(*(uint32_t *)&in->hdr[32]);
maxcmdsn = scsi_get_uint32(&in->hdr[32]);
if (maxcmdsn > iscsi->maxcmdsn) {
iscsi->maxcmdsn = maxcmdsn;
}
@@ -1134,7 +1135,7 @@ struct iscsi_in_pdu *in)
{
uint32_t maxcmdsn;
maxcmdsn = ntohl(*(uint32_t *)&in->hdr[32]);
maxcmdsn = scsi_get_uint32(&in->hdr[32]);
if (maxcmdsn > iscsi->maxcmdsn) {
iscsi->maxcmdsn = maxcmdsn;
}