Restrict intsets and maps to non-negative integers
authorAndy Wingo <wingo@pobox.com>
Thu, 3 Jul 2014 07:37:30 +0000 (09:37 +0200)
committerAndy Wingo <wingo@pobox.com>
Thu, 3 Jul 2014 07:37:30 +0000 (09:37 +0200)
* module/language/cps/intmap.scm (intmap-add):
* module/language/cps/intset.scm (intset-add): Restrict to only hold
  non-negative integers.

module/language/cps/intmap.scm
module/language/cps/intset.scm

index 7be27c9..152985a 100644 (file)
   (match bs
     (($ <intmap> min shift root)
      (cond
+      ((< i 0)
+       ;; The power-of-two spanning trick doesn't work across 0.
+       (error "Intmaps can only map non-negative integers." i))
       ((not val) (intmap-remove bs i))
       ((not root)
        ;; Add first element.
index b235c61..1ec6119 100644 (file)
   (match bs
     (($ <intset> min shift root)
      (cond
+      ((< i 0)
+       ;; The power-of-two spanning trick doesn't work across 0.
+       (error "Intsets can only hold non-negative integers." i))
       ((not root)
        ;; Add first element.
        (let ((min (round-down i shift)))