PDA

View Full Version : error or not error ?



DirectuX
01-03-2020, 17:45
Should this code raise an error ?


uses "console"

dim myvar as DWord = 1
myvar = - myvar
printl myvar
WaitKey

myvar is declared as an unsigned variable. Why is it allowed to compute something below 0 ?

Edit: All the same, if you declare

a variable as byte and assign a value outside the 0-255 range
a variable as boolean that isn't %true nor %false



Regarding this previous question and the last Petr's blog page,
is there a list of all errors caught by thinBasic ?

Petr Schreiber
01-03-2020, 20:15
Hi Sebastian,

what are you observing is overflow. It is not unique to thinBASIC and some algorithms actually benefit from it - according to related article (http://huonw.github.io/blog/2016/04/myths-and-legends-about-integer-overflow-in-rust/) for example hashing algorithms, certain data structures (ring buffers, particularly) and even image codecs.

As thinBASIC already has OPTION BOUNDCHECK ON / OPTION BOUNDCHECK OFF, maybe it would be nice to have something like that for OVERFLOW?


Petr

DirectuX
02-03-2020, 10:03
Hi Sebastian,

what are you observing is overflow. It is not unique to thinBASIC and some algorithms actually benefit from it - according to related article (http://huonw.github.io/blog/2016/04/myths-and-legends-about-integer-overflow-in-rust/) for example hashing algorithms, certain data structures (ring buffers, particularly) and even image codecs.

As thinBASIC already has OPTION BOUNDCHECK ON / OPTION BOUNDCHECK OFF, maybe it would be nice to have something like that for OVERFLOW?


Petr
From the article you mentioned:

These overflow checks can be manually disabled or enabled independently of the compilation mode both globally and at a per-operation level. By checking for overflow in some modes, overflow bugs in Rust code are hopefully found earlier. Furthermore, code that actually wants wrapping behaviour is explicit about this requirement, meaning fewer false positives for both future static analyses and for code that enables overflow checking in all modes.

Yes ! it would help hunting certain bugs. By the way, instructive article, as the one it cites (http://cwe.mitre.org/top25/archive/2019/2019_cwe_top25.html)is.