diff --git a/libguile/strings.c b/libguile/strings.c index 2e766c28c..7bb277daf 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -1015,10 +1015,11 @@ SCM_DEFINE (scm_string, "string", 0, 0, 1, /* Verify that this is a list of chars. */ i = scm_ilength (chrs); + SCM_ASSERT (i >= 0, chrs, SCM_ARG1, FUNC_NAME); + len = (size_t) i; rest = chrs; - SCM_ASSERT (len >= 0, chrs, SCM_ARG1, FUNC_NAME); while (len > 0 && scm_is_pair (rest)) { SCM elt = SCM_CAR (rest); diff --git a/test-suite/tests/strings.test b/test-suite/tests/strings.test index d82a4723d..a35dd20d8 100644 --- a/test-suite/tests/strings.test +++ b/test-suite/tests/strings.test @@ -447,7 +447,17 @@ (string-set! s 4 (integer->char #x010300)) (char=? (string-ref s 4) (integer->char #x010300))))) +;; +;; list->string +;; +(with-test-prefix "string" + (pass-if-exception "convert circular list to string" + exception:wrong-type-arg + (let ((foo (list #\a #\b #\c))) + (set-cdr! (cddr foo) (cdr foo)) + (apply string foo)))) + (with-test-prefix "string-split" ;; in guile 1.6.7 and earlier, character >=128 wasn't matched in the string