Skip to content
Snippets Groups Projects
Verified Commit bf2973e8 authored by Tom Almeida's avatar Tom Almeida
Browse files

Ensure we correctly insert null character in gets

parent d7a0f3d5
No related branches found
No related tags found
No related merge requests found
...@@ -351,10 +351,10 @@ pub extern "C" fn fgets(s: *mut c_char, n: c_int, stream: &mut FILE) -> *mut c_c ...@@ -351,10 +351,10 @@ pub extern "C" fn fgets(s: *mut c_char, n: c_int, stream: &mut FILE) -> *mut c_c
if let Some((rpos, rend)) = stream.read { if let Some((rpos, rend)) = stream.read {
for _ in (0..(n-1) as usize).take_while(|x| rpos + x < rend) { for _ in (0..(n-1) as usize).take_while(|x| rpos + x < rend) {
st[diff] = stream.buf[rpos + diff] as i8; st[diff] = stream.buf[rpos + diff] as i8;
if st[diff] == b'\n' as i8 || st[diff] == stream.buf_char { diff += 1;
if st[diff-1] == b'\n' as i8 || st[diff-1] == stream.buf_char {
break; break;
} }
diff += 1;
} }
stream.read = Some((rpos+diff, rend)); stream.read = Some((rpos+diff, rend));
for i in diff..(n-1) as usize { for i in diff..(n-1) as usize {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment