Code RoomDangling pointer after move
HardPrep Room Coding #2000

Dangling pointer after move

Code reviewCode quality & reviewSenior–Staff~30 min

Review this Rust parser that keeps a pointer to a slice of its own buffer to avoid re-scanning.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 30 min
Mark a line and say what kind of problem it is.0 findings
1struct Parser {
2 buf: String,
3 cursor: *const u8, // points into buf
4}
5 
6impl Parser {
7 fn new(s: String) -> Parser {
8 let cursor = s.as_ptr();
9 Parser { buf: s, cursor }
10 }
11 fn first(&self) -> u8 {
12 unsafe { *self.cursor }
13 }
14}
15 
16let p = Parser::new("hello".into());
17let p2 = p; // move
18let _ = p2.first(); // deref cursor
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.