[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
integer overflow during division
From: |
Bruno Haible |
Subject: |
integer overflow during division |
Date: |
Fri, 19 Feb 2021 18:30:19 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-201-generic; KDE/5.18.0; x86_64; ; ) |
Division by -1 is also known to cause signed integer overflow. In this
case, on x86_64 CPUs, you don't even need a '-ftrapv' option. Test case:
(poke) var x = -4611686018427387904;
(poke) var y = 2*x;
(poke) y / -1
Gleitkomma-Ausnahme (Speicherabzug geschrieben)
In the debugger:
(poke) var x = -4611686018427387904;
(poke) var y = 2*x;
(poke) y / -1
Thread 1 "poke" received signal SIGFPE, Arithmetic exception.
0x00007ffff7b8ea84 in pvm_execute_or_initialize (jitter_initialize=63,
jitter_initial_program_point=0xac5f90,
jitter_original_state=0x632310) at ../../libpoke/pvm.jitter:2325
2325 PVM_CHECKED_BINOP (LONG, LONG, LONG, /);
You should get away without a crash by using the INT_DIVIDE_OVERFLOW
macro from Gnulib's intprops.h.
Bruno
- integer overflow during division,
Bruno Haible <=