Mercurial > vim
comparison src/evalfunc.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 | 27be410d6d29 |
children | 056e32b99e93 |
comparison
equal
deleted
inserted
replaced
10657:d4518c5bfd0b | 10658:77d66e9ac0ab |
---|---|
3302 { | 3302 { |
3303 float_T f = 0.0; | 3303 float_T f = 0.0; |
3304 | 3304 |
3305 if (get_float_arg(argvars, &f) == OK) | 3305 if (get_float_arg(argvars, &f) == OK) |
3306 { | 3306 { |
3307 # ifdef FEAT_NUM64 | 3307 if (f < -VARNUM_MAX) |
3308 if (f < -0x7fffffffffffffffLL) | 3308 rettv->vval.v_number = -VARNUM_MAX; |
3309 rettv->vval.v_number = -0x7fffffffffffffffLL; | 3309 else if (f > VARNUM_MAX) |
3310 else if (f > 0x7fffffffffffffffLL) | 3310 rettv->vval.v_number = VARNUM_MAX; |
3311 rettv->vval.v_number = 0x7fffffffffffffffLL; | |
3312 else | 3311 else |
3313 rettv->vval.v_number = (varnumber_T)f; | 3312 rettv->vval.v_number = (varnumber_T)f; |
3314 # else | |
3315 if (f < -0x7fffffff) | |
3316 rettv->vval.v_number = -0x7fffffff; | |
3317 else if (f > 0x7fffffff) | |
3318 rettv->vval.v_number = 0x7fffffff; | |
3319 else | |
3320 rettv->vval.v_number = (varnumber_T)f; | |
3321 # endif | |
3322 } | 3313 } |
3323 } | 3314 } |
3324 | 3315 |
3325 /* | 3316 /* |
3326 * "floor({float})" function | 3317 * "floor({float})" function |