Do not apply `inf?' or `nan?' to strings
authorMark H Weaver <mhw@netris.org>
Tue, 25 Jan 2011 23:35:22 +0000 (18:35 -0500)
committerAndy Wingo <wingo@pobox.com>
Fri, 28 Jan 2011 11:16:59 +0000 (12:16 +0100)
* module/ice-9/format.scm (format): Test to make sure an argument is a
  number before applying `inf?' and `nan?' to it.  Formerly, format
  would call `inf?' and `nan?' on arguments that might be either a
  number or a string, although those predicates should ideally throw an
  exception when applied to non-number objects.

module/ice-9/format.scm

index 1681004..7cd0183 100644 (file)
@@ -1,5 +1,5 @@
 ;;;; "format.scm" Common LISP text output formatter for SLIB
-;;;    Copyright (C) 2010 Free Software Foundation, Inc.
+;;;    Copyright (C) 2010, 2011 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
               (padch (format:par pars l 4 format:space-ch #f)))
 
           (cond
-           ((or (inf? number) (nan? number))
+           ((and (number? number)
+                 (or (inf? number) (nan? number)))
             (format:out-inf-nan number width digits #f overch padch))
 
            (digits
               (expch (format:par pars l 6 #f #f)))
              
           (cond
-           ((or (inf? number) (nan? number))
+           ((and (number? number)
+                 (or (inf? number) (nan? number)))
             (format:out-inf-nan number width digits edigits overch padch))
 
            (digits                      ; fixed precision
               (overch (if (> l 4) (list-ref pars 4) #f))
               (padch (if (> l 5) (list-ref pars 5) #f)))
           (cond
-           ((or (inf? number) (nan? number))
+           ((and (number? number)
+                 (or (inf? number) (nan? number)))
             ;; FIXME: this isn't right.
             (format:out-inf-nan number width digits edigits overch padch))
            (else
               (padch (format:par pars l 3 format:space-ch #f)))
 
           (cond
-           ((or (inf? number) (nan? number))
+           ((and (number? number)
+                 (or (inf? number) (nan? number)))
             (format:out-inf-nan number width digits #f #f padch))
 
            (else