python: Fix typo in buffer::write.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Thu, 14 Aug 2008 09:48:29 +0000 (10:48 +0100)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Thu, 14 Aug 2008 10:01:43 +0000 (11:01 +0100)
src/gallium/state_trackers/python/p_texture.i

index fd38e0733fb1578088a8024d80f9e7c8f1dff6e6..06bc10546595a8b15e3ccb31664893cb2c54a192 100644 (file)
@@ -183,8 +183,20 @@ struct st_buffer {
       struct pipe_winsys *winsys = $self->st_dev->screen->winsys;
       char *map;
       
+      assert($self->buffer->refcount);
+      
+      if(offset > $self->buffer->size) {
+         PyErr_SetString(PyExc_ValueError, "offset must be smaller than buffer size");
+         return;
+      }
+
+      if(offset + LENGTH > $self->buffer->size) {
+         PyErr_SetString(PyExc_ValueError, "data length must fit inside the buffer");
+         return;
+      }
+
       map = winsys->buffer_map(winsys, $self->buffer, PIPE_BUFFER_USAGE_CPU_WRITE);
-      if(!map) {
+      if(map) {
          memcpy(map + offset, STRING, LENGTH);
          winsys->buffer_unmap(winsys, $self->buffer);
       }