summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src/posix-gfid-path.c
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-21 20:42:53 +0300
committerAmar Tumballi <amarts@redhat.com>2018-08-31 06:15:46 +0000
commit7772315bd7d82d5f06f008dfe767f1e597a41b23 (patch)
treeaa766b174482be034228698a994c8bbf9ac32b84 /xlators/storage/posix/src/posix-gfid-path.c
parentdc6e6b71f87f6f89bb0b69816e92779595d716bd (diff)
multiple xlators (storage/posix): strncpy()->sprintf(), reduce strlen()'s
xlators/storage/posix/src/posix-gfid-path.c xlators/storage/posix/src/posix-handle.c xlators/storage/posix/src/posix-helpers.c xlators/storage/posix/src/posix-inode-fd-ops.c xlators/storage/posix/src/posix.h 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 strlen to SLEN (sizeof() ) for const strings. Compile-tested only! Change-Id: I056939f111a4ec6bc8ebd539ebcaf9eb67da6c95 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'xlators/storage/posix/src/posix-gfid-path.c')
-rw-r--r--xlators/storage/posix/src/posix-gfid-path.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/xlators/storage/posix/src/posix-gfid-path.c b/xlators/storage/posix/src/posix-gfid-path.c
index 686276eb5a9..a08168a3bd4 100644
--- a/xlators/storage/posix/src/posix-gfid-path.c
+++ b/xlators/storage/posix/src/posix-gfid-path.c
@@ -124,6 +124,7 @@ posix_get_gfid2path (xlator_t *this, inode_t *inode, const char *real_path,
struct posix_private *priv = NULL;
char pargfid_str[UUID_CANONICAL_FORM_LEN + 1] = {0,};
gf_boolean_t found = _gf_false;
+ int len;
priv = this->private;
@@ -196,8 +197,8 @@ posix_get_gfid2path (xlator_t *this, inode_t *inode, const char *real_path,
remaining_size = size;
list_offset = 0;
while (remaining_size > 0) {
- strncpy (keybuffer, list + list_offset,
- sizeof(keybuffer));
+ snprintf (keybuffer, sizeof (keybuffer), "%s",
+ list + list_offset);
if (!posix_is_gfid2path_xattr (keybuffer)) {
goto ignore;
@@ -228,8 +229,9 @@ posix_get_gfid2path (xlator_t *this, inode_t *inode, const char *real_path,
i++;
ignore:
- remaining_size -= strlen (keybuffer) + 1;
- list_offset += strlen (keybuffer) + 1;
+ len = strlen (keybuffer);
+ remaining_size -= (len + 1);
+ list_offset += (len + 1);
} /* while (remaining_size > 0) */
/* gfid2path xattr is absent in the list of xattrs */