   [queue cl blocking offset req-size flags ^objects wait-events event]
   (let [err (int-array 1)
         res (CL/clEnqueueMapBuffer queue (cl-mem cl) blocking flags offset
-                                   (min req-size (- (size cl) offset))
+                                   (min (long req-size) (- (long (size cl)) (long offset)))
                                    (if wait-events (alength wait-events) 0)
                                    wait-events event err)]
     (with-check-arr err (.order res (ByteOrder/nativeOrder)))))

  "
  ([kernel x & values]
   (if (integer? x)
     (loop [i x values values]
       (if-let [val (first values)]
         (do (set-arg! kernel i val)
             (recur (inc i) (next values)))

  ([queue cl host blocking offset ^objects wait-events event]
   (with-check
     (CL/clEnqueueWriteBuffer queue (cl-mem cl) blocking offset
                              (min (long (size cl)) (long (size host))) (ptr host)
                              (if wait-events (alength wait-events) 0)
                              wait-events event)
     queue))
