git » libjio » commit 010b827

jread, jwrite and jwritev had a potential bug that a return value of 0 could extend the file or leave the file pointer in an incorrect position. This patch fixes it.

author Alberto Bertogli
2004-09-06 02:46:05 UTC
committer Alberto Bertogli
2007-07-15 13:23:10 UTC
parent 57f40c98510fe34e6a4d83082581a1bb155d43a5

jread, jwrite and jwritev had a potential bug that a return value of 0 could extend the file or leave the file pointer in an incorrect position. This patch fixes it.

jread, jwrite and jwritev had a potential bug that a return value of 0 could
extend the file or leave the file pointer in an incorrect position. This patch
fixes it.

unix.c +6 -6

diff --git a/unix.c b/unix.c
index f0ee5b1..6aaf4f6 100644
--- a/unix.c
+++ b/unix.c
@@ -31,9 +31,9 @@ ssize_t jread(struct jfs *fs, void *buf, size_t count)
 	rv = spread(fs->fd, buf, count, pos);
 	plockf(fs->fd, F_UNLOCK, pos, count);
 
-	if (rv >= 0) {
+	if (rv > 0) {
 		/* if success, advance the file pointer */
-		lseek(fs->fd, count, SEEK_CUR);
+		lseek(fs->fd, rv, SEEK_CUR);
 	}
 
 	pthread_mutex_unlock(&(fs->lock));
@@ -92,9 +92,9 @@ ssize_t jwrite(struct jfs *fs, const void *buf, size_t count)
 
 	rv = jtrans_commit(&ts);
 
-	if (rv >= 0) {
+	if (rv > 0) {
 		/* if success, advance the file pointer */
-		lseek(fs->fd, count, SEEK_CUR);
+		lseek(fs->fd, rv, SEEK_CUR);
 	}
 
 	pthread_mutex_unlock(&(fs->lock));
@@ -143,9 +143,9 @@ ssize_t jwritev(struct jfs *fs, const struct iovec *vector, int count)
 
 	rv = jtrans_commit(&ts);
 
-	if (rv >= 0) {
+	if (rv > 0) {
 		/* if success, advance the file pointer */
-		lseek(fs->fd, sum, SEEK_CUR);
+		lseek(fs->fd, rv, SEEK_CUR);
 	}
 
 	pthread_mutex_unlock(&(fs->lock));