shithub: lwext4

Download patch

ref: 2d9c5b5d776dcaa543b4a37f738617dfca64fff1
parent: cc66c4021879f44ff267298c4a666ae8d78d9e43
parent: d8218c9442655f8bdebb912483d425dded654bfd
author: Grzegorz Kostka <[email protected]>
date: Fri Oct 20 05:40:37 EDT 2017

Merge pull request #33 from enetor/fseek

Use int64_t as offset to ext4_fseek.

--- a/include/ext4.h
+++ b/include/ext4.h
@@ -368,7 +368,7 @@
  *              @ref SEEK_END
  *
  * @return  Standard error code.*/
-int ext4_fseek(ext4_file *file, uint64_t offset, uint32_t origin);
+int ext4_fseek(ext4_file *file, int64_t offset, uint32_t origin);
 
 /**@brief   Get file position.
  *
--- a/src/ext4.c
+++ b/src/ext4.c
@@ -2016,23 +2016,25 @@
 	return r;
 }
 
-int ext4_fseek(ext4_file *file, uint64_t offset, uint32_t origin)
+int ext4_fseek(ext4_file *file, int64_t offset, uint32_t origin)
 {
 	switch (origin) {
 	case SEEK_SET:
-		if (offset > file->fsize)
+		if (offset < 0 || (uint64_t)offset > file->fsize)
 			return EINVAL;
 
 		file->fpos = offset;
 		return EOK;
 	case SEEK_CUR:
-		if ((offset + file->fpos) > file->fsize)
+		if ((offset < 0 && (uint64_t)(-offset) > file->fpos) ||
+		    (offset > 0 &&
+		     (uint64_t)offset > (file->fsize - file->fpos)))
 			return EINVAL;
 
 		file->fpos += offset;
 		return EOK;
 	case SEEK_END:
-		if (offset > file->fsize)
+		if (offset < 0 || (uint64_t)offset > file->fsize)
 			return EINVAL;
 
 		file->fpos = file->fsize - offset;