# HG changeset patch # User Michael Pavone # Date 1406491268 25200 # Node ID 8dbb2d2522a53b5b1abddef35c53a2d84ba79629 # Parent 14b4e540af2820d9043c39cd0dd6a0afcf0f7d66 Fix a crash in from:withLength when given a negative length. Fix a bug in trim that was causing it to give a negative length to from:withLength diff -r 14b4e540af28 -r 8dbb2d2522a5 modules/string.tp --- a/modules/string.tp Sat Jul 26 15:02:01 2014 -0700 +++ b/modules/string.tp Sun Jul 27 13:01:08 2014 -0700 @@ -211,6 +211,12 @@ start <- bytes } clampedLen <- tocopy num + if: clampedLen < 0 { + clampedLen <- bytes - clampedLen + if: clampedLen < 0 { + clampedLen <- 0 + } + } if: start + clampedLen > bytes { clampedLen <- bytes - start } @@ -293,16 +299,16 @@ } do: { start <- start + 1 } - end <- l + end <- l - 1 while: { - if: end > 0 { - b <- byte: end - 1 + if: end > start { + b <- byte: end b = space || b = tab || b = nl || b = cr } } do: { end <- end - 1 } - from: start withLength: (end - start) + from: start withLength: (end + 1 - start) } startsWith? <- :prefix {