From fa6be4be28e552cdae879349d6829b2c8d65ff8b Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Thu, 30 Jan 2014 15:20:44 -0600
Subject: [PATCH] Fixes in Buffer.__getslice__ (pointed out by Freddie
 Witherden)

---
 src/wrapper/wrap_cl.hpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/wrapper/wrap_cl.hpp b/src/wrapper/wrap_cl.hpp
index ea1cea82..4be614a0 100644
--- a/src/wrapper/wrap_cl.hpp
+++ b/src/wrapper/wrap_cl.hpp
@@ -1725,7 +1725,13 @@ namespace pyopencl
         PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
             (data(), CL_MEM_FLAGS, sizeof(my_flags), &my_flags, 0));
 
-        return get_sub_region(start, end, my_flags);
+        flags &= ^CL_MEM_COPY_HOST_PTR;
+
+        if (end <= start)
+          throw pyopencl::error("Buffer.__getitem__", CL_INVALID_VALUE,
+              "Buffer slice have end > start");
+
+        return get_sub_region(start, end-start, my_flags);
       }
 #endif
   };
-- 
GitLab