From c2c0f6cb0d6877e868e75dc7404b5b187b968041 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Sat, 28 Oct 2017 17:55:09 +0200
Subject: [PATCH] Catch negative-size array allocations

---
 pyopencl/array.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/pyopencl/array.py b/pyopencl/array.py
index 6679387d..744dca10 100644
--- a/pyopencl/array.py
+++ b/pyopencl/array.py
@@ -481,9 +481,14 @@ class Array(object):
         self.allocator = allocator
 
         if data is None:
-            if not alloc_nbytes:
-                # Work around CL not allowing zero-sized buffers.
-                alloc_nbytes = 1
+            if alloc_nbytes <= 0:
+                if alloc_nbytes == 0:
+                    # Work around CL not allowing zero-sized buffers.
+                    alloc_nbytes = 1
+
+                else:
+                    raise ValueError("cannot allocate CL buffer with "
+                            "negative size")
 
             if allocator is None:
                 if context is None and queue is not None:
-- 
GitLab