ctdb-protocol: Use ctdb_string marshalling
authorAmitay Isaacs <amitay@gmail.com>
Thu, 21 Apr 2016 13:49:33 +0000 (23:49 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 3 May 2016 02:43:19 +0000 (04:43 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/protocol/protocol_control.c

index ecc7eaa7e40917a4229f27dd5624ecfd953cae6a..d07fd93d72c9773fa0ed9f13b295d1d3dbaf61b6 100644 (file)
@@ -1972,7 +1972,7 @@ int ctdb_reply_control_push(struct ctdb_req_header *h,
 {
        struct ctdb_reply_control_wire *wire;
        uint8_t *buf;
-       size_t length, buflen, datalen, errlen;
+       size_t length, buflen, datalen;
        int ret;
 
        if (reply->status == 0) {
@@ -1981,14 +1981,8 @@ int ctdb_reply_control_push(struct ctdb_req_header *h,
                datalen = 0;
        }
 
-       if (reply->errmsg == NULL) {
-               errlen = 0;
-       } else {
-               errlen = strlen(reply->errmsg) + 1;
-       }
-
        length = offsetof(struct ctdb_reply_control_wire, data) +
-                datalen + errlen;
+                datalen + ctdb_string_len(reply->errmsg);
 
        ret = allocate_pkt(mem_ctx, length, &buf, &buflen);
        if (ret != 0) {
@@ -2007,10 +2001,8 @@ int ctdb_reply_control_push(struct ctdb_req_header *h,
                ctdb_reply_control_data_push(&reply->rdata, wire->data);
        }
 
-       wire->errorlen = errlen;
-       if (errlen > 0) {
-               memcpy(wire->data + datalen, reply->errmsg, wire->errorlen);
-       }
+       wire->errorlen = ctdb_string_len(reply->errmsg);
+       ctdb_string_push(reply->errmsg, wire->data + wire->datalen);
 
        *pkt = buf;
        *pkt_len = buflen;
@@ -2051,12 +2043,10 @@ int ctdb_reply_control_pull(uint8_t *pkt, size_t pkt_len, uint32_t opcode,
                }
        }
 
-       if (wire->errorlen > 0) {
-               reply->errmsg = talloc_memdup(mem_ctx,
-                                             wire->data + wire->datalen,
-                                             wire->errorlen);
-       } else {
-               reply->errmsg = NULL;
+       ret = ctdb_string_pull(wire->data + wire->datalen, wire->errorlen,
+                              mem_ctx, &reply->errmsg);
+       if (ret != 0) {
+               return ret;
        }
 
        return 0;