summaryrefslogtreecommitdiff
path: root/source4/cluster
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-01-22 03:33:12 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:43:57 -0500
commit4109edc5b651cddd15d1d3c1f84f93f9355bf8ee (patch)
tree50f6698b539431365489018926b95b926a622372 /source4/cluster
parent30bfba96d3b7007aa47e037328ea0f2b8e7d1d6e (diff)
downloadsamba-4109edc5b651cddd15d1d3c1f84f93f9355bf8ee.tar.gz
samba-4109edc5b651cddd15d1d3c1f84f93f9355bf8ee.tar.bz2
samba-4109edc5b651cddd15d1d3c1f84f93f9355bf8ee.zip
r20943: use offsetof() instead of sizeof() - 1 for the packet length
calculations. It will be interesting to see how portable this is. The advantage over the sizeof() method is that it avoids padding problems after the data[1] array. That was causing us to get valgrind errors. (This used to be commit fd8e46043903d3650f8f33dcab165800f6869b1d)
Diffstat (limited to 'source4/cluster')
-rw-r--r--source4/cluster/ctdb/common/ctdb_call.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/source4/cluster/ctdb/common/ctdb_call.c b/source4/cluster/ctdb/common/ctdb_call.c
index 26451c4cfe..7883be8a0a 100644
--- a/source4/cluster/ctdb/common/ctdb_call.c
+++ b/source4/cluster/ctdb/common/ctdb_call.c
@@ -125,7 +125,7 @@ static void ctdb_send_error(struct ctdb_context *ctdb,
va_list ap;
struct ctdb_reply_error *r;
char *msg;
- int len;
+ int msglen, len;
va_start(ap, fmt);
msg = talloc_vasprintf(ctdb, fmt, ap);
@@ -134,17 +134,19 @@ static void ctdb_send_error(struct ctdb_context *ctdb,
}
va_end(ap);
- len = strlen(msg)+1;
- r = ctdb->methods->allocate_pkt(ctdb, sizeof(*r) - 1 + len);
+ msglen = strlen(msg)+1;
+ len = offsetof(struct ctdb_reply_error, msg);
+ r = ctdb->methods->allocate_pkt(ctdb, len + msglen);
CTDB_NO_MEMORY_FATAL(ctdb, r);
- r->hdr.length = sizeof(*r) - 1 + len;
+
+ r->hdr.length = len + msglen;
r->hdr.operation = CTDB_REPLY_ERROR;
r->hdr.destnode = hdr->srcnode;
r->hdr.srcnode = ctdb->vnn;
r->hdr.reqid = hdr->reqid;
r->status = status;
- r->msglen = len;
- memcpy(&r->msg[0], msg, len);
+ r->msglen = msglen;
+ memcpy(&r->msg[0], msg, msglen);
talloc_free(msg);
@@ -192,7 +194,7 @@ static void ctdb_call_send_dmaster(struct ctdb_context *ctdb,
struct ctdb_req_dmaster *r;
int len;
- len = sizeof(*r) - 1 + key->dsize + data->dsize;
+ len = offsetof(struct ctdb_req_dmaster, data) + key->dsize + data->dsize;
r = ctdb->methods->allocate_pkt(ctdb, len);
CTDB_NO_MEMORY_FATAL(ctdb, r);
r->hdr.length = len;
@@ -234,7 +236,7 @@ void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr
struct ctdb_reply_dmaster *r;
TDB_DATA key, data;
struct ctdb_ltdb_header header;
- int ret;
+ int ret, len;
key.dptr = c->data;
key.dsize = c->keylen;
@@ -268,9 +270,10 @@ void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr
}
/* send the CTDB_REPLY_DMASTER */
- r = ctdb->methods->allocate_pkt(ctdb, sizeof(*r) - 1 + data.dsize);
+ len = offsetof(struct ctdb_reply_dmaster, data) + data.dsize;
+ r = ctdb->methods->allocate_pkt(ctdb, len);
CTDB_NO_MEMORY_FATAL(ctdb, r);
- r->hdr.length = sizeof(*r) - 1 + data.dsize;
+ r->hdr.length = len;
r->hdr.operation = CTDB_REPLY_DMASTER;
r->hdr.destnode = c->dmaster;
r->hdr.srcnode = ctdb->vnn;
@@ -299,7 +302,7 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
struct ctdb_req_call *c = (struct ctdb_req_call *)hdr;
TDB_DATA key, data, call_data, reply_data;
struct ctdb_reply_call *r;
- int ret;
+ int ret, len;
struct ctdb_ltdb_header header;
key.dptr = c->data;
@@ -339,9 +342,10 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
call_data.dsize?&call_data:NULL,
&reply_data, c->hdr.srcnode);
- r = ctdb->methods->allocate_pkt(ctdb, sizeof(*r) - 1 + reply_data.dsize);
+ len = offsetof(struct ctdb_reply_call, data) + reply_data.dsize;
+ r = ctdb->methods->allocate_pkt(ctdb, len);
CTDB_NO_MEMORY_FATAL(ctdb, r);
- r->hdr.length = sizeof(*r) - 1 + reply_data.dsize;
+ r->hdr.length = len;
r->hdr.operation = CTDB_REPLY_CALL;
r->hdr.destnode = hdr->srcnode;
r->hdr.srcnode = hdr->destnode;
@@ -564,7 +568,7 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_context *ctdb,
state = talloc_zero(ctdb, struct ctdb_call_state);
CTDB_NO_MEMORY_NULL(ctdb, state);
- len = sizeof(*state->c) - 1 + key.dsize + (call_data?call_data->dsize:0);
+ len = offsetof(struct ctdb_req_call, data) + key.dsize + (call_data?call_data->dsize:0);
state->c = ctdb->methods->allocate_pkt(ctdb, len);
CTDB_NO_MEMORY_NULL(ctdb, state->c);