summaryrefslogtreecommitdiff
path: root/tests/pixbuf-scale-two-step.c
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2017-02-20 09:21:13 +0000
committerPhilip Withnall <withnall@endlessm.com>2017-08-03 12:08:38 +0100
commit861a6dbea289d1ed98af1f66eb8024bc04464bd9 (patch)
treefe5434c24f153a1e7fcbe79968bd67640cf9dba8 /tests/pixbuf-scale-two-step.c
parent48accc7397d6802f3faa0fb9a4024babc980a09a (diff)
downloadgdk-pixbuf-861a6dbea289d1ed98af1f66eb8024bc04464bd9.tar.gz
tests: Add some assertions to check for zero-dimensioned images
This could happen if something in the test fails, so this allows early diagnosis of problems. It also hints to Coverity that the loops which follow can’t run (almost) infinitely due to the loop bounds being inverted. Coverity IDs: 1391987, 1399712 https://bugzilla.gnome.org/show_bug.cgi?id=778943
Diffstat (limited to 'tests/pixbuf-scale-two-step.c')
-rw-r--r--tests/pixbuf-scale-two-step.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/tests/pixbuf-scale-two-step.c b/tests/pixbuf-scale-two-step.c
index 8050b30c5..d3f68861a 100644
--- a/tests/pixbuf-scale-two-step.c
+++ b/tests/pixbuf-scale-two-step.c
@@ -62,26 +62,30 @@ pixdata_almost_equal (GdkPixbuf *one, GdkPixbuf *two)
guchar *two_row; /* Pointer to start of row of pixels in two */
guchar *two_pixel; /* Pointer to current pixel data in two */
guint x, y;
+ gint width_one, height_one;
- g_assert_cmpint (gdk_pixbuf_get_height (one), >=, 0);
- g_assert_cmpint (gdk_pixbuf_get_width (one), >=, 0);
+ width_one = gdk_pixbuf_get_width (one);
+ height_one = gdk_pixbuf_get_height (one);
+
+ g_assert_cmpint (height_one, >=, 0);
+ g_assert_cmpint (width_one, >=, 0);
g_assert_cmpint (gdk_pixbuf_get_height (two), >=, 0);
g_assert_cmpint (gdk_pixbuf_get_width (two), >=, 0);
- if (gdk_pixbuf_get_width (one) != gdk_pixbuf_get_width (two) ||
- gdk_pixbuf_get_height (one) != gdk_pixbuf_get_height (two))
+ if (width_one != gdk_pixbuf_get_width (two) ||
+ height_one != gdk_pixbuf_get_height (two))
{
g_test_fail();
}
for (y = 0, one_row = gdk_pixbuf_get_pixels (one),
two_row = gdk_pixbuf_get_pixels (two);
- y < gdk_pixbuf_get_height (one);
+ y < height_one;
y++, one_row += gdk_pixbuf_get_rowstride (one),
two_row += gdk_pixbuf_get_rowstride (two))
{
for (x = 0, one_pixel = one_row, two_pixel = two_row;
- x < gdk_pixbuf_get_width(one);
+ x < width_one;
x++, one_pixel += gdk_pixbuf_get_n_channels (one),
two_pixel += gdk_pixbuf_get_n_channels (two))
{
@@ -188,21 +192,28 @@ crop_n_compare(const GdkPixbuf *source, /* The source image */
guchar *cropped_row; /* Pointer to start of row of pixels in cropped */
guchar *cropped_pixel; /* Pointer to current pixel data in cropped */
guint x, y;
+ gint scaled_width, scaled_height;
+
+ scaled_width = gdk_pixbuf_get_width (scaled);
+ scaled_height = gdk_pixbuf_get_height (scaled);
+
+ g_assert (scaled_width > 0);
+ g_assert (scaled_height > 0);
- if (gdk_pixbuf_get_width (scaled) != gdk_pixbuf_get_width (cropped) ||
- gdk_pixbuf_get_height (scaled) != gdk_pixbuf_get_height (cropped))
+ if (scaled_width != gdk_pixbuf_get_width (cropped) ||
+ scaled_height != gdk_pixbuf_get_height (cropped))
{
g_test_fail();
}
for (y = 0, scaled_row = gdk_pixbuf_get_pixels (scaled),
cropped_row = gdk_pixbuf_get_pixels (cropped);
- y < gdk_pixbuf_get_height (scaled);
+ y < scaled_height;
y++, scaled_row += gdk_pixbuf_get_rowstride (scaled),
cropped_row += gdk_pixbuf_get_rowstride (cropped))
{
for (x = 0, scaled_pixel = scaled_row, cropped_pixel = cropped_row;
- x < gdk_pixbuf_get_width(scaled);
+ x < scaled_width;
x++, scaled_pixel += gdk_pixbuf_get_n_channels (scaled),
cropped_pixel += gdk_pixbuf_get_n_channels (cropped))
{