From 7772315bd7d82d5f06f008dfe767f1e597a41b23 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Tue, 21 Aug 2018 20:42:53 +0300 Subject: 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 --- xlators/storage/posix/src/posix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xlators/storage/posix/src/posix.h') diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h index b53afdf4b59..5b013b4b516 100644 --- a/xlators/storage/posix/src/posix.h +++ b/xlators/storage/posix/src/posix.h @@ -300,7 +300,7 @@ typedef struct { char gfid_str[64] = {0}; \ uuid_utoa_r (gfid, gfid_str); \ path_len = strlen (base_path) + 1 + \ - strlen (GF_UNLINK_PATH) + 1 + \ + SLEN (GF_UNLINK_PATH) + 1 + \ strlen (gfid_str) + 1; \ unlink_path = alloca (path_len); \ if (!unlink_path) { \ -- cgit