The bug is an example of a problem associated with inductive inference. Relying on induction is tempting, and in most cases sufficient.
However, this case proves that one should always be aware of the potential fallacy that is inherent in induction.
Including, as I found to my embarassment recently, my license key generation logic.
Turns out that the maximum for a Java integer happens in the middle of the numerical representations of the values that I thought were valid license keys. "Whoops!"
(Happily, it turns out that all the keys actually assigned to customers were accepted by the broken version of the checker, too.)
In this particular context, however, that should be just fine: low is clearly initialized to zero, and then only set to the value of this expression +1. As such, barring other bugs, low can never be negative.
Your point is valid, though, and worth bearing in mind in other circumstances.
9 comments
[ 2.1 ms ] story [ 34.3 ms ] threadTurns out that the maximum for a Java integer happens in the middle of the numerical representations of the values that I thought were valid license keys. "Whoops!"
(Happily, it turns out that all the keys actually assigned to customers were accepted by the broken version of the checker, too.)
Your point is valid, though, and worth bearing in mind in other circumstances.