Skip to content

Commit f2314b1

Browse files
committed
---
yaml --- r: 143803 b: refs/heads/try2 c: e053bff h: refs/heads/master i: 143801: e90e332 143799: b211004 v: v3
1 parent 56ed20f commit f2314b1

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 5eaa4d1d2f6eafc4233892d3d1dafb0d05799ac3
8+
refs/heads/try2: e053bff5d0c83a5b36afcaf4c58a40a27162ec0f
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/c_str.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ pub struct CStringIterator<'self> {
148148

149149
impl<'self> Iterator<libc::c_char> for CStringIterator<'self> {
150150
fn next(&mut self) -> Option<libc::c_char> {
151-
if self.ptr.is_null() {
151+
let ch = unsafe { *self.ptr };
152+
if ch == 0 {
152153
None
153154
} else {
154-
let ch = unsafe { *self.ptr };
155155
self.ptr = ptr::offset(self.ptr, 1);
156156
Some(ch)
157157
}
@@ -163,6 +163,7 @@ mod tests {
163163
use super::*;
164164
use libc;
165165
use ptr;
166+
use option::{Some, None};
166167

167168
#[test]
168169
fn test_to_c_str() {
@@ -210,7 +211,23 @@ mod tests {
210211
#[should_fail]
211212
#[ignore(cfg(windows))]
212213
fn test_with_ref_empty_fail() {
213-
let c_str = CString::new(ptr::null(), false);
214+
let c_str = unsafe { CString::new(ptr::null(), false) };
214215
c_str.with_ref(|_| ());
215216
}
217+
218+
#[test]
219+
fn test_iterator() {
220+
let c_str = "".to_c_str();
221+
let mut iter = c_str.iter();
222+
assert_eq!(iter.next(), None);
223+
224+
let c_str = "hello".to_c_str();
225+
let mut iter = c_str.iter();
226+
assert_eq!(iter.next(), Some('h' as libc::c_char));
227+
assert_eq!(iter.next(), Some('e' as libc::c_char));
228+
assert_eq!(iter.next(), Some('l' as libc::c_char));
229+
assert_eq!(iter.next(), Some('l' as libc::c_char));
230+
assert_eq!(iter.next(), Some('o' as libc::c_char));
231+
assert_eq!(iter.next(), None);
232+
}
216233
}

0 commit comments

Comments
 (0)