summaryrefslogtreecommitdiffstats
path: root/xlators/features/changelog/lib/src
diff options
context:
space:
mode:
authorHarshavardhana <harsha@harshavardhana.net>2014-05-21 13:30:02 -0700
committerVenky Shankar <vshankar@redhat.com>2014-05-27 23:23:09 -0700
commit38b2531d91e51dc73ba99ebcd3b98db75affa7d7 (patch)
tree754833cf8a1478b576a0bc6953871a1f14fcffb6 /xlators/features/changelog/lib/src
parent048902f108ad3c437e83248c14de33e6519d9f07 (diff)
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 <harsha@harshavardhana.net> Reviewed-on: http://review.gluster.org/7836 Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-by: Venky Shankar <vshankar@redhat.com> Tested-by: Venky Shankar <vshankar@redhat.com>
Diffstat (limited to 'xlators/features/changelog/lib/src')
-rw-r--r--xlators/features/changelog/lib/src/gf-changelog.c15
-rw-r--r--xlators/features/changelog/lib/src/gf-history-changelog.c15
2 files changed, 16 insertions, 14 deletions
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;
}
/**
diff --git a/xlators/features/changelog/lib/src/gf-history-changelog.c b/xlators/features/changelog/lib/src/gf-history-changelog.c
index a895037eeca..d1a6b0e9c89 100644
--- a/xlators/features/changelog/lib/src/gf-history-changelog.c
+++ b/xlators/features/changelog/lib/src/gf-history-changelog.c
@@ -147,7 +147,7 @@ gf_history_changelog_start_fresh ()
ssize_t
gf_history_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;
@@ -171,18 +171,19 @@ gf_history_changelog_next_change (char *bufptr, size_t maxlen)
tracker_fd = hist_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;
}
/**