This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix crash of ffs (0x80000000) on 64 bit


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;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]