diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-05-18 06:29:06 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-05-18 06:29:06 -0700 |
commit | 97fce155c0b92429b9deabfca31e35dbb5fe0d8f (patch) | |
tree | 08c0fada23ba0d93127e6dae0998f0a652963bdb | |
parent | 6ca427f995a76ed9c5bae2ab86f864ea5ae4d376 (diff) | |
download | txr-97fce155c0b92429b9deabfca31e35dbb5fe0d8f.tar.gz txr-97fce155c0b92429b9deabfca31e35dbb5fe0d8f.tar.bz2 txr-97fce155c0b92429b9deabfca31e35dbb5fe0d8f.zip |
Handle integer overflow in length_list.
* lib.c (length_list): Count using cnum
only up to INT_PTR_MAX, then switch to
bignums.
-rw-r--r-- | lib.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -2629,14 +2629,26 @@ val proper_list_p(val obj) val length_list(val list) { cnum len = 0; + val bn_len; gc_hint(list); - while (consp(list)) { + while (consp(list) && len < INT_PTR_MAX) { len++; list = cdr(list); } - return num(len); + + if (len < INT_PTR_MAX) + return num(len); + + bn_len = num(INT_PTR_MAX); + + while (consp(list)) { + bn_len = succ(bn_len); + list = cdr(list); + } + + return bn_len; } val getplist(val list, val key) |