top | item 43458013

(no title)

vijaybritto | 11 months ago

I have a naive question here.

Could this have been avoided if they had used Rust? Or is this a bug that can happen even in Rust code too?

discuss

order

probably_wrong|11 months ago

The original bug was returning STATUS_SUCCESS to indicate that a function had succeeded without noticing that STATUS_SUCCESS is defined as 0 in a function that's expected to return a non-zero value on success. This specific error could have happened on any language - defining two different return types and using the wrong one could happen in any language.

andy12_|11 months ago

> defining two different return types and using the wrong one could happen in any language

This specifically is the kind of bug that is avoided with strong typing. The compiler screams at you when using the wrong return type. For example, if a callback expects a Result type, you must return a Result type, not some random int-like value whose definition of success and failure is arbitrary.

surajrmal|11 months ago

It can be avoided in any compiled language that has a boolean type. That includes C these days. Unfortunately this functionality predates the existence of the boolean type.