Dominique Pelle wrote: > I ran "make test" with vim-7.3.712 compiled with IOC > (http://embed.cs.utah.edu/ioc/), a tool that detects integer > overflows, which behave in undefined way according to > the C standard. Only unsigned integer is guaranteed to > behave in a predictable way. IOC found a few bugs:
The actual problem is in the standard. Having integer operations behave in an undefined way is not very useful. They should have defined uniform behavior. It's the compiler writers who like these things to be undefined, not the users. > CLANG ARITHMETIC UNDEFINED at <hashtab.c, (179:25)> : Op: +, Reason : > Signed Addition Overflow, BINARY OPERATION: left (int32): 2140052020 > right (int32): 1608754829 > > CLANG ARITHMETIC UNDEFINED at <misc2.c, (4005:36)> : Op: *, Reason : > Signed Multiplication Overflow, BINARY OPERATION: left (int32): 64087 > right (int32): 64086CLANG ARITHMETIC UNDEFINED at <misc2.c, (3981:6)> > : Op: *, Reason : Signed Multiplication Overflow, BINARY OPERATION: > left ( > > CLANG ARITHMETIC UNDEFINED at <misc2.c, (3981:6)> : Op: *, Reason : > Signed Multiplication Overflow, BINARY OPERATION: left (int32): 64087 > right (int32): 64086 > > Attached patch fixes them. Thanks, I'll add it to the todo list. > There is one more undefined behavior operation (float divide by 0 > which is also undefined in C). Fixing it would require to use the > INFINITY macro I think but it's C99 macro and Vim needs to compile on > older compilers so I did not fix it: Undefined? I thought divide by zero always results in INF. What compiler does otherwise? > CLANG ARITHMETIC UNDEFINED at <eval.c, (4901:15)> : Op: /, Reason : > Floating Division: Divisor is 0, BINARY OPERATION: left (double): > 1.000000 right (double): 0.000000 > > It could be fixed by checking for INFINITY in autoconf. > > There might be more of such bugs: IOC is runtime checker so it only > checked what was executed while running "make test". These might not be bugs, compilers often do more sensible things than what C99 defines. C99 is not a very good standard, it drifted away from the goal to make the language more useful for programmers. Although such a tool can find possible problems, there would also need to be a compiler that actually does something wrong with the code. -- hundred-and-one symptoms of being an internet addict: 21. Your dog has its own home page. /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org /// -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
