> On Sat, May 6, 2017 at 8:45 PM, James McCoy <[email protected]> wrote:
> > On Fri, May 05, 2017 at 10:23:49PM +0200, Bram Moolenaar wrote:
> >> James McCoy wrote:
> >> > It would be nice for there to be defined behavior here for the user,
> >> > instead of exposing them to the whims of the compiler implementation.
> >>
> >> Unfortunately, that is quite difficult. I propose the compiler standard
> >> gets fixed. This means only the few compilers that exist need to take
> >> care of this, instead of the millions of C programs.
> >
> > Since that's unlikely to happen, how about fixing it in one editor
> > instead of passing it off to all the Vim users?
> >
>
> I'm willing to help implement it. Unfortunately, the most
> straightforward solution, using `-ftrapv` and catching the resulting
> SIGABRT when overflow occurs, suffers from a bug in GCC dating from
> '08: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35412. `-ftrapv`
> does seem to work in the current release of Cygwin, but did not work
> last I tried it on Linux.
>
> A possible workaround is the combination of `-fsanitize=undefined`,
> `-fsanitize=signed-integer-overflow`, and
> `-fsanitize-undefined-trap-on-error`. The last flag given does not
> seem to be documented. When it is used to compile a test program under
> Cygwin and that program executed I receive an illegal instruction core
> dump. I have yet to test it on a GNU/Linux toolchain.
>
> ```
> #include <signal.h>
> #include <stdio.h>
> #include <limits.h>
>
> void
> handler(int signum)
> {
> printf("Overflow detected.\n");
> }
>
> int
> main(int argc, char *argv[])
> {
> int i = INT_MAX;
> signal(SIGABRT, &handler);
> i++;
>
> return 0;
> }
> ```
>
> `gcc -ftrapv`
> `gcc --fsanitize=undefined -fsanitize=signed-integer-overflow
> -fsanitize-undefined-trap-on-error`
You can try it, but I suspect there are several places we depend on
overflow to work normally. Esp. in the encryption code (it has a
runtime test to check that this works).
--
<Beeth> Girls are like internet domain names,
the ones I like are already taken.
<honx> Well, you can stil get one from a strange country :-P
/// 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
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.