3 ms·
Um, yes. That jumped out at me. If there's a no-find, the code will de-reference null and crash. That's just not acceptable. Try to write that in Rust, using S
by Animats 6y ago
Um, yes. That jumped out at me. If there's a no-find, the code will de-reference null and crash. That's just not acceptable. Try to write that in Rust, using Some(ref) for the forward link, and the compiler will force you to test for None and detect the end of the list.
This is pre-1990s programming style. I've seen such code in assembly programs. Because I was reading crash dumps where it failed.
- souprock 6y agoIt's 100% acceptable. You should not remove something from a list unless you know it is there. Since you won't attempt to remove something that doesn't exist, any code to check for that situation is an unjustified performance loss. (separate code exists for searching a list) This... is not Python. C programmers, particularly kernel developers, have that style even in 2020.
- Animats 6y agoI hope not. Kernel programmers need to be paranoid. This is a classic idea for doubly linked lists. The empty list has the head element linked to itself in both directions. Buffer rings are sometimes organized that way. The cases for doubly linked lists are messier. Bear in mind that in modern CPUs, branches to nearby code are almost free, but indirection to far memory is expensive.