[gegl] matting-levin: Fix stack smashing
- From: Daniel Sabo <daniels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] matting-levin: Fix stack smashing
- Date: Mon, 9 Dec 2013 11:10:18 +0000 (UTC)
commit 17105d463b482a14894cce45d8f6700af3409e37
Author: Daniel Sabo <DanielSabo gmail com>
Date: Mon Dec 9 02:33:52 2013 -0800
matting-levin: Fix stack smashing
Allocating 10MB stack frames is unhealthy.
operations/external/matting-levin.c | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/operations/external/matting-levin.c b/operations/external/matting-levin.c
index 1af27cd..1cbff3f 100644
--- a/operations/external/matting-levin.c
+++ b/operations/external/matting-levin.c
@@ -880,8 +880,8 @@ matting_sparse_elems (const sparse_t *s)
static gboolean
matting_verify (const sparse_t *s)
{
- guint i, j;
- gboolean rows[s->rows];
+ guint i, j;
+ gboolean *rows;
/* Must be a square matrix */
g_return_val_if_fail (s->columns == s->rows, FALSE);
@@ -906,16 +906,30 @@ matting_verify (const sparse_t *s)
* not a requirement of the UMFPACK format; rather, something we expect of
* the matrix from the matting algorithm.
*/
+ rows = g_new (gboolean, s->rows);
+
for (i = 0; i < s->rows; ++i)
rows [i] = FALSE;
for (i = 0; i < matting_sparse_elems (s); ++i)
{
guint row = s->row_idx[i];
- g_return_val_if_fail (row < s->rows, FALSE);
+ if (!(row < s->rows))
+ {
+ g_free (rows);
+ g_return_val_if_reached (FALSE);
+ }
rows[row] = TRUE;
}
for (i = 0; i < s->rows; ++i)
- g_return_val_if_fail (rows[i], FALSE);
+ {
+ if (!rows[i])
+ {
+ g_free (rows);
+ g_return_val_if_reached (FALSE);
+ }
+ }
+
+ g_free (rows);
return TRUE;
}
@@ -1076,7 +1090,7 @@ matting_get_laplacian (const gdouble *restrict image,
}
{
- gdouble row_sum[image_elems];
+ gdouble *row_sum = g_new (gdouble, image_elems);
/* Calculate the sum of all the elements in each row */
for (i = 0; i < image_elems; ++i)
@@ -1115,6 +1129,8 @@ matting_get_laplacian (const gdouble *restrict image,
g_warn_if_fail (float_cmp (row_sum [i], 0.0) ||
float_cmp (row_sum [i], lambda));
}
+
+ g_free (row_sum);
}
g_warn_if_fail (trip_cursor == trip_nz);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]