summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-05-31 19:00:36 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-05-31 19:00:36 -0700
commit71bddaf115efcab36f55f35557990173962f47e4 (patch)
treed2b5691d736ce190732635a3d4267e9edf02d5f6
parentcf57f49f7c5911617645031a87ece0fadd787dcc (diff)
downloadtxr-71bddaf115efcab36f55f35557990173962f47e4.tar.gz
txr-71bddaf115efcab36f55f35557990173962f47e4.tar.bz2
txr-71bddaf115efcab36f55f35557990173962f47e4.zip
bugfix: list length: off-by-one error huge lists.
* lib.c (length_list, length_proper_list): Fix off-by-one bug when calculating lengths of lists that overflow the cnum type. Note that we will never see regular lists which hit this situation, because there are more values in the range [0, INT_PTR_MAX] then there are possible pointers in the system, However, lazy lists can be that long or longer, because as we calculate the length of a lazy list, the part we have already traversed can be garbage-collected under the right circumstances.
-rw-r--r--lib.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 6ac23b46..e3e1909e 100644
--- a/lib.c
+++ b/lib.c
@@ -3127,6 +3127,7 @@ val length_list(val list)
if (len < INT_PTR_MAX)
return num(len);
+ list = cdr(list);
bn_len = num(INT_PTR_MAX);
while (consp(list)) {
@@ -3152,6 +3153,7 @@ static val length_proper_list(val list)
if (len < INT_PTR_MAX)
return num(len);
+ list = cdr(list);
bn_len = num(INT_PTR_MAX);
while (list) {