comparison modules/string.tp @ 306:8dbb2d2522a5

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
author Michael Pavone <pavone@retrodev.com>
date Sun, 27 Jul 2014 13:01:08 -0700
parents 14b4e540af28
children 74cab9b5f2a4
comparison
equal deleted inserted replaced
305:14b4e540af28 306:8dbb2d2522a5
209 } 209 }
210 if: start > bytes { 210 if: start > bytes {
211 start <- bytes 211 start <- bytes
212 } 212 }
213 clampedLen <- tocopy num 213 clampedLen <- tocopy num
214 if: clampedLen < 0 {
215 clampedLen <- bytes - clampedLen
216 if: clampedLen < 0 {
217 clampedLen <- 0
218 }
219 }
214 if: start + clampedLen > bytes { 220 if: start + clampedLen > bytes {
215 clampedLen <- bytes - start 221 clampedLen <- bytes - start
216 } 222 }
217 ret <- make_object: (addr_of: string_meta) NULL 0 223 ret <- make_object: (addr_of: string_meta) NULL 0
218 ret data!: (GC_MALLOC_ATOMIC: clampedLen + 1) 224 ret data!: (GC_MALLOC_ATOMIC: clampedLen + 1)
291 b = space || b = tab || b = nl || b = cr 297 b = space || b = tab || b = nl || b = cr
292 } 298 }
293 } do: { 299 } do: {
294 start <- start + 1 300 start <- start + 1
295 } 301 }
296 end <- l 302 end <- l - 1
297 while: { 303 while: {
298 if: end > 0 { 304 if: end > start {
299 b <- byte: end - 1 305 b <- byte: end
300 b = space || b = tab || b = nl || b = cr 306 b = space || b = tab || b = nl || b = cr
301 } 307 }
302 } do: { 308 } do: {
303 end <- end - 1 309 end <- end - 1
304 } 310 }
305 from: start withLength: (end - start) 311 from: start withLength: (end + 1 - start)
306 } 312 }
307 313
308 startsWith? <- :prefix { 314 startsWith? <- :prefix {
309 if: (prefix length) <= length { 315 if: (prefix length) <= length {
310 0 = (compareSub: prefix 0 0 (prefix length)) 316 0 = (compareSub: prefix 0 0 (prefix length))