diff mbox

[2/2] libc: fix sign extension in fallocate()

Message ID 1442324925-29609-2-git-send-email-yuriy.kolerov@synopsys.com
State New
Headers show

Commit Message

Yuriy Kolerov Sept. 15, 2015, 1:48 p.m. UTC
Signed-off-by: Yuriy Kolerov <yuriy.kolerov@synopsys.com>
---
 libc/sysdeps/linux/common/fallocate.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/libc/sysdeps/linux/common/fallocate.c b/libc/sysdeps/linux/common/fallocate.c
index 97ac303..d953a46 100644
--- a/libc/sysdeps/linux/common/fallocate.c
+++ b/libc/sysdeps/linux/common/fallocate.c
@@ -21,14 +21,12 @@  int attribute_hidden __libc_fallocate(int fd, int mode, __off_t offset, __off_t
 	int ret;
 
 # if __WORDSIZE == 32
-	uint32_t off_low = offset;
-	uint32_t len_low = len;
-	/* may assert that these >>31 are 0 */
-	uint32_t zero = 0;
+	int32_t offset_sign_extension = (offset < 0) ? 0xFFFFFFFF : 0;
+	int32_t len_sign_extension = (len < 0) ? 0xFFFFFFFF : 0;
 	INTERNAL_SYSCALL_DECL(err);
 	ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode,
-		__LONG_LONG_PAIR(zero, off_low),
-		__LONG_LONG_PAIR(zero, len_low)));
+		__LONG_LONG_PAIR(offset_sign_extension, offset),
+		__LONG_LONG_PAIR(len_sign_extension, len)));
 # elif __WORDSIZE == 64
 	INTERNAL_SYSCALL_DECL(err);
 	ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, mode, offset, len));