diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-08-21 18:25:33 +0300 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-08-24 16:26:36 +0000 |
commit | 938849a417727c85f1925dde641b3c6c54c71275 (patch) | |
tree | be05eab666860bd2fb486b5c51eb622e57275efd /cli/src/cli-rpc-ops.c | |
parent | 036327d9e963c84a5222f8d1c7598ab36ad46a4b (diff) |
{cli-cmd-parser|cli-rpc-ops||cli-xml-output}.c: strncpy()->sprintf(), reduce strlen()'s
strncpy may not be very efficient for short strings copied into
a large buffer: If the length of src is less than n,
strncpy() writes additional null bytes to dest to ensure
that a total of n bytes are written.
Instead, use snprintf().
Also:
- save the result of strlen() and re-use it when possible.
- move from GF_CALLOC() to GF_MALLOC() for the strings.
- move from strlen to sizeof() for const strings.
Compile-tested only!
Change-Id: I3cf49c5401ee100a5db6a4954c3d699ec1814c17
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'cli/src/cli-rpc-ops.c')
-rw-r--r-- | cli/src/cli-rpc-ops.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 9812bbdab18..1e95836e4af 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -5936,8 +5936,8 @@ write_contents_to_common_pem_file (dict_t *dict, int output_count) goto out; } /* Adding the new line character */ - bytes_written = sys_write (fd, "\n", strlen("\n")); - if (bytes_written != strlen("\n")) { + bytes_written = sys_write (fd, "\n", 1); + if (bytes_written != 1) { gf_log ("", GF_LOG_ERROR, "Failed to add new line char"); ret = -1; @@ -12027,10 +12027,10 @@ gf_cli_bitrot_cbk (struct rpc_req *req, struct iovec *iov, ret = 0; goto out; case GF_BITROT_OPTION_TYPE_SCRUB: - if (!strncmp ("pause", scrub_cmd, strlen("pause"))) + if (!strncmp ("pause", scrub_cmd, sizeof ("pause"))) cli_out("volume bitrot: scrubber paused " "for volume %s", volname); - if (!strncmp ("resume", scrub_cmd, strlen("resume"))) + if (!strncmp ("resume", scrub_cmd, sizeof ("resume"))) cli_out("volume bitrot: scrubber resumed " "for volume %s", volname); ret = 0; |