Browse Source

Merge pull request #78 from Tommoa/master

Yet another fix for strcspn and strspn.
Jeremy Soller 7 years ago
parent
commit
b09435f17d
1 changed files with 8 additions and 8 deletions
  1. 8 8
      src/string/src/lib.rs

+ 8 - 8
src/string/src/lib.rs

@@ -125,7 +125,7 @@ pub unsafe extern "C" fn strcspn(s1: *const c_char, s2: *const c_char) -> c_ulon
 
     // The below logic is effectively ripped from the musl implementation
 
-    let mut byteset = [0u8; 32 / mem::size_of::<usize>()];
+    let mut byteset = [0usize; 32 / mem::size_of::<usize>()];
 
     let mut i = 0;
     while *s2.offset(i) != 0 {
@@ -135,9 +135,9 @@ pub unsafe extern "C" fn strcspn(s1: *const c_char, s2: *const c_char) -> c_ulon
     }
 
     i = 0; // reset
-    while *s2.offset(i) != 0 {
-        if byteset[(*s2.offset(i) as usize) / (8 * byteset.len())]
-            & 1 << (*s2.offset(i) as usize % (8 * byteset.len())) > 0
+    while *s1.offset(i) != 0 {
+        if byteset[(*s1.offset(i) as usize) / (8 * byteset.len())]
+            & 1 << (*s1.offset(i) as usize % (8 * byteset.len())) > 0
         {
             break;
         }
@@ -277,7 +277,7 @@ pub unsafe extern "C" fn strspn(s1: *const c_char, s2: *const c_char) -> c_ulong
 
     // The below logic is effectively ripped from the musl implementation
 
-    let mut byteset = [0u8; 32 / mem::size_of::<usize>()];
+    let mut byteset = [0usize; 32 / mem::size_of::<usize>()];
 
     let mut i = 0;
     while *s2.offset(i) != 0 {
@@ -287,9 +287,9 @@ pub unsafe extern "C" fn strspn(s1: *const c_char, s2: *const c_char) -> c_ulong
     }
 
     i = 0; // reset
-    while *s2.offset(i) != 0 {
-        if byteset[(*s2.offset(i) as usize) / (8 * byteset.len())]
-            & 1 << (*s2.offset(i) as usize % (8 * byteset.len())) < 1
+    while *s1.offset(i) != 0 {
+        if byteset[(*s1.offset(i) as usize) / (8 * byteset.len())]
+            & 1 << (*s1.offset(i) as usize % (8 * byteset.len())) < 1
         {
             break;
         }