Conversation
|
r? @clarfonthey rustbot has assigned @clarfonthey. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
This should probably have an associated codegen test too. |
|
I'm not sure we can make a codegen test for it since codegen tests use the prebuilt stdlib where overflow checks are disabled? |
|
If you explicitly use a |
|
In general I am very skeptical about adding
Of course, the downside of range metadata is that we can only add it in a few places, and rustc so far mostly (entirely?) applies it based on types. So we'd have to declare Edit: oh, maybe it's enough to change the return type of the Rust |
|
Moderately interested enough in that approach to want to try it right now. Going to do some investigating. |
A colleague of mine was trying to remove all panics in a Linux kernel driver, and noticed the machine code had a panic on
len + 1inCStr::from_ptrin the stdlib here:But clearly there's never actually overflow here.
By adding an
assert_uncheckedinstrlen(), this overflow check infrom_ptris optimized out. By adding it here instead of just doinglen.unchecked_add(1), we also get benefits to other callers ofstrlen. For instance, if an end-user callsCStr::from_ptr(ptr).len()to get the length, this assertion benefits that caller too.