There was just a nginx issue that highlights how problematic the use of unsigned is in this context: CVE -2026-123007
For why I think it's unrealistic to go all-in on signed integers in C, it's because sizeof is unsigned, and most APIs dealing with lengths use size_t, and there are lot of pitfalls when mixing signed and unsigned types.
But I agree that there's a good case for using signed for the task behind that CVE. As I said, there are compelling reasons. But OpenSSL is a case study in the pitfalls with mixing signed and unsigned in C code.
With unsigned you only need one check: 'i < bound', it works always, regardless how i is computed, and it doesn't matter if the calculation overflowed or wrapped around, still works.
With signed you need: 'i >= 0 && i < bound', and you need to be very careful how you calculate i because overflow is undefined behavior.
If `bound` is unsigned and experiences accidental wrap-around due to underflow, the simple `i < bound` check fails open: most values of i pass against the unintentionally-huge `bound`. The signed version fails closed (no i passes both i >= 0 and i < bound), which is usually safer.
That’s how the argument goes, anyway. You’re right that using signed means a missing `>= 0` check can be a problem, as well as all the risks of signed-overflow UB.
No perfect solution in C.
Not that are wraparound CVEs in Rust as well, so there is no perfect solution even outside of C.
You have fuzzing, test coverage checks, overflow checks, static analysis, llm review. There is no conceivable reason why you might have a problem with using an u16 for a buffer length.
Even reading the PR comments shows that these libraries are just really low quality.
They are discussing if they should check the error return on callsites now that they made a function fallible.