mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 03:30:27 +02:00
Fix hashing of empty vectors.
Fixes a bug introduced in cc1cd04f81
"Fix hashing of vectors to run in bounded time."
* libguile/hash.c (scm_hasher): Avoid division by zero.
* test-suite/tests/hash.test ("hash"): Add tests.
This commit is contained in:
parent
f974224d97
commit
63d869e74c
2 changed files with 14 additions and 3 deletions
|
@ -245,7 +245,7 @@ scm_hasher(SCM obj, unsigned long n, size_t d)
|
|||
{
|
||||
i = len;
|
||||
h = n - 1;
|
||||
d2 = (d - 1) / len;
|
||||
d2 = len > 0 ? (d - 1) / len : 0;
|
||||
}
|
||||
|
||||
while (i--)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
;;;; hash.test --- test guile hashing -*- scheme -*-
|
||||
;;;;
|
||||
;;;; Copyright (C) 2004, 2005, 2006, 2008, 2011, 2012 Free Software Foundation, Inc.
|
||||
;;;; Copyright (C) 2004, 2005, 2006, 2008, 2011, 2012,
|
||||
;;;; 2014 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
|
||||
|
@ -36,7 +37,17 @@
|
|||
(pass-if (= 0 (hash noop 1)))
|
||||
(pass-if (= 0 (hash +inf.0 1)))
|
||||
(pass-if (= 0 (hash -inf.0 1)))
|
||||
(pass-if (= 0 (hash +nan.0 1))))
|
||||
(pass-if (= 0 (hash +nan.0 1)))
|
||||
(pass-if (= 0 (hash '#() 1)))
|
||||
|
||||
(pass-if "cyclic vectors"
|
||||
(let ()
|
||||
(define (cyclic-vector n)
|
||||
(let ((v (make-vector n)))
|
||||
(vector-fill! v v)
|
||||
v))
|
||||
(and (= 0 (hash (cyclic-vector 3) 1))
|
||||
(= 0 (hash (cyclic-vector 10) 1))))))
|
||||
|
||||
;;;
|
||||
;;; hashv
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue