Re:Catching integer overflows with template metaprogramming ...
by kentonv on Monday March 27, 2017 @10:42AM
(#13968097)
For my purposes, I would be happy with a way that I can specify constraints specifically in certain critical code sections, where I'd be happy to work around some false positives. Most other code could go on ignoring overflow as it does today.
But for a static analyser, your options are:
1. Model i as a single value, and simulate all ~400,000 passes through the loops. Slow - you basically have to run the program at compile time.
2. Same but truncate the simulation after, say, 20 loops on the assumption that most bugs would have been found on the first few passes. This misses the bug in the second loop.
3. Model i as "Integer in the range -99,999 to +99,999" and generate a false alarm on the first loop.
4. Support arbitrarily complex symbolic values. Difficult - as the value of a variable might depend on complicated business logic.
I guess the benefit of starting a new programming language is you can choose option 3 and say "Working code is illegal, deal with it" from the start.