Fix type-checking in the optimized path of `string=?'.
authorLudovic Courtès <ludo@gnu.org>
Mon, 12 Jul 2010 15:31:38 +0000 (17:31 +0200)
committerLudovic Courtès <ludo@gnu.org>
Mon, 12 Jul 2010 22:08:09 +0000 (00:08 +0200)
* libguile/srfi-13.c (scm_string_eq): Properly type-check S1 and S2.

* test-suite/tests/strings.test ("string=?")["1st argument EOF", "2nd
  argument EOF"]: New tests exposing the problem.

libguile/srfi-13.c
test-suite/tests/strings.test

index eec2961..e9bf94e 100644 (file)
@@ -1168,7 +1168,8 @@ SCM_DEFINE (scm_string_eq, "string=", 2, 4, 0,
            "value otherwise.")
 #define FUNC_NAME s_scm_string_eq
 {
-  if (SCM_LIKELY (scm_i_is_narrow_string (s1) == scm_i_is_narrow_string (s2)
+  if (SCM_LIKELY (scm_is_string (s1) && scm_is_string (s2) &&
+                 scm_i_is_narrow_string (s1) == scm_i_is_narrow_string (s2)
                  && SCM_UNBNDP (start1) && SCM_UNBNDP (end1)
                  && SCM_UNBNDP (start2) && SCM_UNBNDP (end2)))
     {
index e04c026..fa8e6e1 100644 (file)
@@ -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, 2008, 2009 Free Software Foundation, Inc.
+;;;; Copyright (C) 1999, 2001, 2004, 2005, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
 ;;;; 
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
 
     (pass-if-exception "2nd argument symbol"
       exception:wrong-type-arg
-      (string=? "a" 'b))))
+      (string=? "a" 'b))
+
+    (pass-if-exception "1st argument EOF"
+      exception:wrong-type-arg
+      (string=? (with-input-from-string "" read) "b"))
+
+    (pass-if-exception "2nd argument EOF"
+      exception:wrong-type-arg
+      (string=? "a" (with-input-from-string "" read)))))
 
 ;;
 ;; string<?