* hash with zero size
@ 2004-07-04 23:48 Kevin Ryde
0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2004-07-04 23:48 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 405 bytes --]
Calling
(hash #t 0)
kills guile with a divide-by-zero, whereas I'd have hoped probably for
an out-of-range error throw.
* hash.c (scm_hashq, scm_hashv, scm_hash): Restrict to size>=1 rather
than just size>=0, since 0<=hash<size cannot be satisfied when
size==0, and such a size causes divide-by-zeros in scm_hasher.
This would be for the 1.6 branch too, it's the same there.
[-- Attachment #2: hash.c.zero.diff --]
[-- Type: text/plain, Size: 1249 bytes --]
--- hash.c.~1.53.~ 2004-04-15 10:58:00.000000000 +1000
+++ hash.c 2004-07-03 13:46:58.000000000 +1000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997, 2000, 2001, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997, 2000, 2001, 2003, 2004 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
@@ -171,7 +171,7 @@
"different values, since @code{foo} will be garbage collected.")
#define FUNC_NAME s_scm_hashq
{
- SCM_VALIDATE_INUM_MIN (2, size, 0);
+ SCM_VALIDATE_INUM_MIN (2, size, 1);
return SCM_MAKINUM (scm_ihashq (key, SCM_INUM (size)));
}
#undef FUNC_NAME
@@ -207,7 +207,7 @@
"different values, since @code{foo} will be garbage collected.")
#define FUNC_NAME s_scm_hashv
{
- SCM_VALIDATE_INUM_MIN (2, size, 0);
+ SCM_VALIDATE_INUM_MIN (2, size, 1);
return SCM_MAKINUM (scm_ihashv (key, SCM_INUM (size)));
}
#undef FUNC_NAME
@@ -230,7 +230,7 @@
"integer in the range 0 to @var{size} - 1.")
#define FUNC_NAME s_scm_hash
{
- SCM_VALIDATE_INUM_MIN (2, size, 0);
+ SCM_VALIDATE_INUM_MIN (2, size, 1);
return SCM_MAKINUM (scm_ihash (key, SCM_INUM (size)));
}
#undef FUNC_NAME
[-- Attachment #3: hash.test --]
[-- Type: text/plain, Size: 2018 bytes --]
;;;; hash.test --- test guile hashing -*- scheme -*-
;;;;
;;;; Copyright (C) 2004 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
;;;; License as published by the Free Software Foundation; either
;;;; version 2.1 of the License, or (at your option) any later version.
;;;;
;;;; This library is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;;; Lesser General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(define-module (test-suite test-numbers)
#:use-module (test-suite lib)
#:use-module (ice-9 documentation))
;;;
;;; hash
;;;
(with-test-prefix "hash"
(pass-if (->bool (object-documentation hash)))
(pass-if-exception "hash #t -1" exception:out-of-range
(hash #t -1))
(pass-if-exception "hash #t 0" exception:out-of-range
(hash #t 0))
(pass-if (= 0 (hash #t 1)))
(pass-if (= 0 (hash #f 1)))
(pass-if (= 0 (hash noop 1))))
;;;
;;; hashv
;;;
(with-test-prefix "hashv"
(pass-if (->bool (object-documentation hashv)))
(pass-if-exception "hashv #t -1" exception:out-of-range
(hashv #t -1))
(pass-if-exception "hashv #t 0" exception:out-of-range
(hashv #t 0))
(pass-if (= 0 (hashv #t 1)))
(pass-if (= 0 (hashv #f 1)))
(pass-if (= 0 (hashv noop 1))))
;;;
;;; hashq
;;;
(with-test-prefix "hashq"
(pass-if (->bool (object-documentation hashq)))
(pass-if-exception "hashq #t -1" exception:out-of-range
(hashq #t -1))
(pass-if-exception "hashq #t 0" exception:out-of-range
(hashq #t 0))
(pass-if (= 0 (hashq #t 1)))
(pass-if (= 0 (hashq #f 1)))
(pass-if (= 0 (hashq noop 1))))
[-- Attachment #4: Type: text/plain, Size: 143 bytes --]
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-07-04 23:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-04 23:48 hash with zero size Kevin Ryde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).