[gtk+] texture: Add sanity checks to constructors



commit 38b25599d8834ca2cca72ac2f86117b13b22c942
Author: Benjamin Otte <otte redhat com>
Date:   Fri Feb 2 14:58:39 2018 +0100

    texture: Add sanity checks to constructors
    
    width, height and GL texture ID may not be 0, so return_if_fail() if
    they are.

 gdk/gdktexture.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 69721ca..a8afe84 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -319,6 +319,9 @@ gdk_texture_new_for_data (const guchar *data,
   cairo_surface_t *original, *copy;
   cairo_t *cr;
 
+  g_return_val_if_fail (width > 0, NULL);
+  g_return_val_if_fail (height > 0, NULL);
+
   original = cairo_image_surface_create_for_data ((guchar *) data, CAIRO_FORMAT_ARGB32, width, height, 
stride);
   copy = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
 
@@ -353,6 +356,8 @@ gdk_texture_new_for_surface (cairo_surface_t *surface)
   GdkCairoTexture *texture;
 
   g_return_val_if_fail (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE, NULL);
+  g_return_val_if_fail (cairo_image_surface_get_width (surface) > 0, NULL);
+  g_return_val_if_fail (cairo_image_surface_get_height (surface) > 0, NULL);
 
   texture = g_object_new (GDK_TYPE_CAIRO_TEXTURE,
                           "width", cairo_image_surface_get_width (surface),
@@ -720,6 +725,9 @@ gdk_texture_new_for_gl (GdkGLContext   *context,
   GdkGLTexture *self;
 
   g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
+  g_return_val_if_fail (id != 0, NULL);
+  g_return_val_if_fail (width > 0, NULL);
+  g_return_val_if_fail (height > 0, NULL);
 
   self = g_object_new (GDK_TYPE_GL_TEXTURE,
                        "width", width,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]