This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH] Fix crash of ffs (0x80000000) on 64 bit
- From: Christian Franke <Christian dot Franke at t-online dot de>
- To: cygwin-patches at cygwin dot com
- Date: Tue, 23 Sep 2014 18:01:18 +0200
- Subject: [PATCH] Fix crash of ffs (0x80000000) on 64 bit
- Authentication-results: sourceware.org; auth=none
This fixes the issue reported here:
https://cygwin.com/ml/cygwin/2014-09/msg00341.html
On 64 bit, i = 0x80000000 results in x = 0xffffffff80000000 due to sign
extension.
Christian
2014-09-23 Christian Franke <franke@computer.org>
* syscall.cc (ffs): Fix crash of ffs (0x80000000) on 64 bit.
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 15ebf49..044e003 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -3847,10 +3847,9 @@ ffs (int i)
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
};
- unsigned long int a;
- unsigned long int x = i & -i;
+ unsigned x = i & -i;
- a = x <= 0xffff ? (x <= 0xff ? 0 : 8) : (x <= 0xffffff ? 16 : 24);
+ int a = x <= 0xffff ? (x <= 0xff ? 0 : 8) : (x <= 0xffffff ? 16 : 24);
return table[x >> a] + a;
}