From 38b2531d91e51dc73ba99ebcd3b98db75affa7d7 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 21 May 2014 13:30:02 -0700 Subject: features/changelog: NULL termination after memcpy should be of dest pointer snippet code < ..memcpy (bufff, src, len - 1); ..*(src + len) = '\0'; ---> Wrong! > Source buffer lvalue() referencing with offset style NULL termination is wrong and unnecessary when we have a destination buffer, it is the destination buffer which should look to be NULL terminated Makes it more readable and also clearly logical. < ..memcpy (bufff, src, len - 1); ..bufff[len -1] = '\0'; ---> Correct! > Change-Id: I6d7f312aaa5c541f0345649ff1ef9f193892b674 BUG: 1099986 Signed-off-by: Harshavardhana Reviewed-on: http://review.gluster.org/7836 Reviewed-by: Raghavendra Bhat Reviewed-by: Venky Shankar Tested-by: Venky Shankar --- xlators/features/changelog/lib/src/gf-changelog.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'xlators/features/changelog/lib/src/gf-changelog.c') diff --git a/xlators/features/changelog/lib/src/gf-changelog.c b/xlators/features/changelog/lib/src/gf-changelog.c index f74d8effe95..0240aeb0086 100644 --- a/xlators/features/changelog/lib/src/gf-changelog.c +++ b/xlators/features/changelog/lib/src/gf-changelog.c @@ -307,7 +307,7 @@ gf_changelog_start_fresh () ssize_t gf_changelog_next_change (char *bufptr, size_t maxlen) { - ssize_t size = 0; + ssize_t size = -1; int tracker_fd = 0; xlator_t *this = NULL; gf_changelog_t *gfc = NULL; @@ -326,18 +326,19 @@ gf_changelog_next_change (char *bufptr, size_t maxlen) tracker_fd = gfc->gfc_fd; size = gf_readline (tracker_fd, buffer, maxlen); - if (size < 0) + if (size < 0) { + size = -1; goto out; + } + if (size == 0) - return 0; + goto out; memcpy (bufptr, buffer, size - 1); - *(buffer + size) = '\0'; + bufptr[size - 1] = '\0'; +out: return size; - - out: - return -1; } /** -- cgit