[gdk-pixbuf] Use g_try_malloc_n where it makes sense
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf] Use g_try_malloc_n where it makes sense
- Date: Thu, 19 Dec 2013 04:16:52 +0000 (UTC)
commit deb78d971c4bcb9e3ccbb71e7925bc6baa707188
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Dec 18 23:16:16 2013 -0500
Use g_try_malloc_n where it makes sense
This lets us avoid some manual overflow checks.
gdk-pixbuf/gdk-pixbuf.c | 9 ++-------
gdk-pixbuf/gdk-pixdata.c | 2 +-
gdk-pixbuf/io-tga.c | 7 +------
3 files changed, 4 insertions(+), 14 deletions(-)
---
diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c
index 0e13f27..cdef863 100644
--- a/gdk-pixbuf/gdk-pixbuf.c
+++ b/gdk-pixbuf/gdk-pixbuf.c
@@ -431,7 +431,6 @@ gdk_pixbuf_new (GdkColorspace colorspace,
guchar *buf;
int channels;
int rowstride;
- gsize bytes;
g_return_val_if_fail (colorspace == GDK_COLORSPACE_RGB, NULL);
g_return_val_if_fail (bits_per_sample == 8, NULL);
@@ -446,11 +445,7 @@ gdk_pixbuf_new (GdkColorspace colorspace,
/* Always align rows to 32-bit boundaries */
rowstride = (rowstride + 3) & ~3;
- bytes = height * rowstride;
- if (bytes / rowstride != height) /* overflow */
- return NULL;
-
- buf = g_try_malloc (bytes);
+ buf = g_try_malloc_n (height, rowstride);
if (!buf)
return NULL;
@@ -484,7 +479,7 @@ gdk_pixbuf_copy (const GdkPixbuf *pixbuf)
size = gdk_pixbuf_get_byte_length (pixbuf);
- buf = g_try_malloc (size * sizeof (guchar));
+ buf = g_try_malloc (size);
if (!buf)
return NULL;
diff --git a/gdk-pixbuf/gdk-pixdata.c b/gdk-pixbuf/gdk-pixdata.c
index 99129fe..fcba391 100644
--- a/gdk-pixbuf/gdk-pixdata.c
+++ b/gdk-pixbuf/gdk-pixdata.c
@@ -437,7 +437,7 @@ gdk_pixbuf_from_pixdata (const GdkPixdata *pixdata,
copy_pixels = TRUE;
if (copy_pixels)
{
- data = g_try_malloc (pixdata->rowstride * pixdata->height);
+ data = g_try_malloc_n (pixdata->height, pixdata->rowstride);
if (!data)
{
g_set_error (error, GDK_PIXBUF_ERROR,
diff --git a/gdk-pixbuf/io-tga.c b/gdk-pixbuf/io-tga.c
index e6e9ce1..71cb526 100644
--- a/gdk-pixbuf/io-tga.c
+++ b/gdk-pixbuf/io-tga.c
@@ -253,12 +253,7 @@ static GdkPixbuf *get_contiguous_pixbuf (guint width,
if (rowstride / channels != width)
return NULL;
- bytes = height * rowstride;
-
- if (bytes / rowstride != height)
- return NULL;
-
- pixels = g_try_malloc (bytes);
+ pixels = g_try_malloc_n (height, rowstride);
if (!pixels)
return NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]