summaryrefslogtreecommitdiffstats
path: root/xlators/features/changelog/src/changelog-misc.h
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-21 19:23:01 +0300
committerAmar Tumballi <amarts@redhat.com>2018-08-31 06:14:47 +0000
commitdc6e6b71f87f6f89bb0b69816e92779595d716bd (patch)
treee9fbd7f4384a6ccb05a3537b064588ee30f1b6be /xlators/features/changelog/src/changelog-misc.h
parent058d215174b93b3aa14be99073979f45642e519e (diff)
changelog xlator: strncpy()->sprintf(), reduce strlen()'s
xlators/features/changelog/lib/src/gf-changelog-journal-handler.c xlators/features/changelog/lib/src/gf-changelog.c xlators/features/changelog/src/changelog-helpers.c xlators/features/changelog/src/changelog-misc.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(). Where possible, ensure there's no truncation of the output. Also: - save the result of strlen() and re-use it when possible. - move from strlen to SLEN (sizeof() ) for const strings. - switch a strncpy to a memcpy. Compile-tested only! Change-Id: Ia7a52bce0b243613ad910192ec163c93d944e077 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'xlators/features/changelog/src/changelog-misc.h')
-rw-r--r--xlators/features/changelog/src/changelog-misc.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/xlators/features/changelog/src/changelog-misc.h b/xlators/features/changelog/src/changelog-misc.h
index 93af201879e..e96533f7365 100644
--- a/xlators/features/changelog/src/changelog-misc.h
+++ b/xlators/features/changelog/src/changelog-misc.h
@@ -86,13 +86,13 @@
} while (0)
#define CHANGELOG_FILL_HTIME_DIR(changelog_dir, path) do { \
- strncpy (path, changelog_dir, sizeof (path) - 1); \
- strcat (path, "/htime"); \
+ snprintf (path, sizeof (path), "%s/htime", \
+ changelog_dir); \
} while(0)
#define CHANGELOG_FILL_CSNAP_DIR(changelog_dir, path) do { \
- strncpy (path, changelog_dir, sizeof (path) - 1); \
- strcat (path, "/csnap"); \
+ snprintf (path, sizeof (path), "%s/csnap", \
+ changelog_dir); \
} while(0)
/**
* everything after 'CHANGELOG_TYPE_METADATA_XATTR' are internal types