From ecb8d666753cc536105538b178a9eaf8874dafdf Mon Sep 17 00:00:00 2001 From: srijan-sivakumar Date: Mon, 21 Sep 2020 19:14:01 +0530 Subject: glusterd: Removing strlen and using existing len field of data_t Issue: The strlen being used to find the length of the dictionary is an extra step as there already exists len field in data_t which contains the same value. Code Change : 1. Replacing the strlen with len. 2. Removing a typecast which wasn't required. Fixes: #1497 Change-Id: I2780c3876b17b8825038d222fb489a87e090411f Signed-off-by: srijan-sivakumar --- xlators/mgmt/glusterd/src/glusterd-store.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index af6a6be5d5c..de932826c90 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -702,9 +702,11 @@ _storeopts(dict_t *dict_value, char *key, data_t *value, void *data) /* * The option_len considers the length of the key value - * pair and along with that '=' and '\n'. + * pair and along with that '=' and '\n', but as value->len + * already considers a NULL at the end of the data, adding + * just 1. */ - option_len = strlen(key) + strlen((char *)value->data) + 2; + option_len = strlen(key) + value->len + 1; if ((VOLINFO_BUFFER_SIZE - dict_data->buffer_len - 1) < option_len) { ret = gf_store_save_items(shandle->fd, dict_data->buffer); @@ -716,7 +718,7 @@ _storeopts(dict_t *dict_value, char *key, data_t *value, void *data) dict_data->buffer[0] = '\0'; } ret = snprintf(dict_data->buffer + dict_data->buffer_len, option_len + 1, - "%s=%s\n", key, (char *)value->data); + "%s=%s\n", key, value->data); if (ret < 0 || ret > option_len + 1) { gf_smsg(this->name, GF_LOG_ERROR, EINVAL, GD_MSG_COPY_FAIL, NULL); return -1; -- cgit