comparison src/eval.c @ 10658:77d66e9ac0ab v8.0.0219

patch 8.0.0219: ubsan reports errors for overflow commit https://github.com/vim/vim/commit/7a40ea2138102545848ea86a361f1b8dec7552b5 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 22 18:34:57 2017 +0100 patch 8.0.0219: ubsan reports errors for overflow Problem: Ubsan reports errors for integer overflow. Solution: Define macros for minimum and maximum values. Select an expression based on the value. (Mike Williams)
author Christian Brabandt <cb@256bit.org>
date Sun, 22 Jan 2017 18:45:04 +0100
parents 553f9b9502bc
children 8ba322dad776
comparison
equal deleted inserted replaced
10657:d4518c5bfd0b 10658:77d66e9ac0ab
4107 n1 = n1 * n2; 4107 n1 = n1 * n2;
4108 else if (op == '/') 4108 else if (op == '/')
4109 { 4109 {
4110 if (n2 == 0) /* give an error message? */ 4110 if (n2 == 0) /* give an error message? */
4111 { 4111 {
4112 #ifdef FEAT_NUM64
4113 if (n1 == 0) 4112 if (n1 == 0)
4114 n1 = -0x7fffffffffffffffLL - 1; /* similar to NaN */ 4113 n1 = VARNUM_MIN; /* similar to NaN */
4115 else if (n1 < 0) 4114 else if (n1 < 0)
4116 n1 = -0x7fffffffffffffffLL; 4115 n1 = -VARNUM_MAX;
4117 else 4116 else
4118 n1 = 0x7fffffffffffffffLL; 4117 n1 = VARNUM_MAX;
4119 #else
4120 if (n1 == 0)
4121 n1 = -0x7fffffffL - 1L; /* similar to NaN */
4122 else if (n1 < 0)
4123 n1 = -0x7fffffffL;
4124 else
4125 n1 = 0x7fffffffL;
4126 #endif
4127 } 4118 }
4128 else 4119 else
4129 n1 = n1 / n2; 4120 n1 = n1 / n2;
4130 } 4121 }
4131 else 4122 else