mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-13 17:20:21 +02:00
Fix sloppy bound checking in `string-{ref,set!}' with the empty string.
* libguile/strings.c (scm_string_ref): Add proper range checking for the empty string. (scm_string_set_x): Likewise. Reported by Bill Schottstaedt <bil@ccrma.Stanford.EDU>. * test-suite/tests/strings.test ("string-ref"): New test prefix. ("string-set!")["empty string", "empty string and non-zero index", "out of range", "negative index", "regular string"]: New tests. * NEWS: Update.
This commit is contained in:
parent
0affe15f63
commit
deee086c8d
3 changed files with 66 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
;;;; strings.test --- test suite for Guile's string functions -*- scheme -*-
|
||||
;;;; Jim Blandy <jimb@red-bean.com> --- August 1999
|
||||
;;;;
|
||||
;;;; Copyright (C) 1999, 2001, 2004, 2005, 2006 Free Software Foundation, Inc.
|
||||
;;;; Copyright (C) 1999, 2001, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
|
||||
;;;;
|
||||
;;;; This program is free software; you can redistribute it and/or modify
|
||||
;;;; it under the terms of the GNU General Public License as published by
|
||||
|
@ -160,15 +160,62 @@
|
|||
(eq? (char-ci>=? (integer->char 0) (integer->char 255))
|
||||
(string-ci>=? (string-ints 0) (string-ints 255)))))
|
||||
|
||||
;;
|
||||
;; string-ref
|
||||
;;
|
||||
|
||||
(with-test-prefix "string-ref"
|
||||
|
||||
(pass-if-exception "empty string"
|
||||
exception:out-of-range
|
||||
(string-ref "" 0))
|
||||
|
||||
(pass-if-exception "empty string and non-zero index"
|
||||
exception:out-of-range
|
||||
(string-ref "" 123))
|
||||
|
||||
(pass-if-exception "out of range"
|
||||
exception:out-of-range
|
||||
(string-ref "hello" 123))
|
||||
|
||||
(pass-if-exception "negative index"
|
||||
exception:out-of-range
|
||||
(string-ref "hello" -1))
|
||||
|
||||
(pass-if "regular string"
|
||||
(char=? (string-ref "GNU Guile" 4) #\G)))
|
||||
|
||||
;;
|
||||
;; string-set!
|
||||
;;
|
||||
|
||||
(with-test-prefix "string-set!"
|
||||
|
||||
(pass-if-exception "empty string"
|
||||
exception:out-of-range
|
||||
(string-set! (string-copy "") 0 #\x))
|
||||
|
||||
(pass-if-exception "empty string and non-zero index"
|
||||
exception:out-of-range
|
||||
(string-set! (string-copy "") 123 #\x))
|
||||
|
||||
(pass-if-exception "out of range"
|
||||
exception:out-of-range
|
||||
(string-set! (string-copy "hello") 123 #\x))
|
||||
|
||||
(pass-if-exception "negative index"
|
||||
exception:out-of-range
|
||||
(string-set! (string-copy "hello") -1 #\x))
|
||||
|
||||
(pass-if-exception "read-only string"
|
||||
exception:read-only-string
|
||||
(string-set! (substring/read-only "abc" 0) 1 #\space)))
|
||||
(string-set! (substring/read-only "abc" 0) 1 #\space))
|
||||
|
||||
(pass-if "regular string"
|
||||
(let ((s (string-copy "GNU guile")))
|
||||
(string-set! s 4 #\G)
|
||||
(char=? (string-ref s 4) #\G))))
|
||||
|
||||
|
||||
(with-test-prefix "string-split"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue