Fixing wcsrtombs
This commit is contained in:
committed by
Jeremy Soller
parent
b25bbae2e0
commit
82eb083091
@@ -321,28 +321,33 @@ pub unsafe extern "C" fn wcsrtombs(
|
||||
}
|
||||
|
||||
while n >= 4 {
|
||||
if **ws.wrapping_sub(1) >= 0x7f {
|
||||
if (**ws).wrapping_sub(1) >= 0x7f {
|
||||
if **ws == 0 {
|
||||
*s = 0;
|
||||
*ws = 0 as *const wchar_t;
|
||||
return N.wrapping_sub(n);
|
||||
}
|
||||
|
||||
l = wcrtomb(s, **ws, ptr::null_mut());
|
||||
if l.wrapping_add(1) == 0 {
|
||||
return usize::MAX;
|
||||
}
|
||||
|
||||
s = s.offset(l as isize);
|
||||
n = n.wrapping_sub(l);
|
||||
} else {
|
||||
|
||||
let new_s = s;
|
||||
s = s.offset(1);
|
||||
*new_s = **ws as c_char;
|
||||
n = n.wrapping_sub(1);
|
||||
}
|
||||
|
||||
*ws = (*ws).offset(1);
|
||||
}
|
||||
|
||||
while n != 0 {
|
||||
if **ws.wrapping_sub(1) >= 0x7f {
|
||||
if (**ws).wrapping_sub(1) >= 0x7f {
|
||||
if **ws == 0 {
|
||||
*s = 0;
|
||||
*ws = 0 as *const wchar_t;
|
||||
@@ -366,6 +371,7 @@ pub unsafe extern "C" fn wcsrtombs(
|
||||
}
|
||||
*ws = (*ws).offset(1);
|
||||
}
|
||||
|
||||
return N;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,11 @@ int main() {
|
||||
const wchar_t *wcs1 = L"";
|
||||
size_t mb_len1 = wcsrtombs(NULL, &wcs1, 0, NULL);
|
||||
assert(mb_len1 == 0);
|
||||
|
||||
|
||||
const wchar_t *wcs2 = L"Hello, world!";
|
||||
size_t mb_len2 = wcsrtombs(NULL, &wcs2, 0, NULL);
|
||||
assert(mb_len2 == strlen("Hello, world!"));
|
||||
|
||||
|
||||
char *mbs2 = malloc(mb_len2 + 1);
|
||||
wcsrtombs(mbs2, &wcs2, mb_len2 + 1, NULL);
|
||||
assert(strcmp(mbs2, "Hello, world!") == 0);
|
||||
|
||||
Reference in New Issue
Block a user