[Openmcl-devel] Is it safe to make hash tables with non-standard tests?

Ron Garret ron at flownet.com
Mon Jul 15 01:02:58 UTC 2013


EQUALP doesn't do the Right Thing with symbols:

? (equalp 'foo "FOO")
NIL
? (string= 'foo "FOO")
T

Also, EQUALP is a security risk.  It's vulnerable to denial-of-service attacks if you feed it e.g. a circular list.

rg

On Jul 14, 2013, at 4:49 PM, Tom Emerson wrote:

> You don't need to: using 'equal as your test achieves the same result.
> 
> Welcome to Clozure Common Lisp Version 1.9-r15757  (LinuxX8664)!
> ? (defvar foo (make-hash-table :test 'equal))
> #<HASH-TABLE :TEST EQUAL size 0/60 #x3020006F2C3D>
> ? (setf (gethash "abc" foo) 100)
> 100
> ? (gethash "abc" foo)
> 100
> T
> ? (gethash "ABC" foo)
> NIL
> NIL
> 
> If instead you want the test to be string-equal then use 'equalp
> 
> ? (setq foo (make-hash-table :test 'equalp))
> #<HASH-TABLE :TEST EQUALP size 0/60 #x3020006F9D5D>
> ? (setf (gethash "abc" foo) 100)
> 100
> ? (gethash "abc" foo)
> 100
> T
> ? (gethash "ABC" foo)
> 100
> T
> 
> This is portable: same results in SBCL.
> 
> 
> 
> On Sun, Jul 14, 2013 at 3:53 PM, Ron Garret <ron at flownet.com> wrote:
> I need a string= hash table, which is not in the standard.  It appears that CCL can actually make one:
> 
> (make-hash-table :test 'string= :hash-function 'sxhash)
> 
> This seems to do the Right Thing, but  it's not documented.  Is it safe to use this feature?
> 
> rg
> 
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
> 
> 
> 
> -- 
> Tom Emerson
> tremerson at gmail.com
> http://www.dreamersrealm.net/tree

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.clozure.com/pipermail/openmcl-devel/attachments/20130714/408f8bf6/attachment.html>


More information about the Openmcl-devel mailing list