diff options
author | Vincent Sanders <vince@kyllikki.org> | 2016-08-31 15:19:46 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2016-08-31 15:19:46 +0100 |
commit | 988e0d0819c7e6b068b1c1741a50b547f8414cf7 (patch) | |
tree | 6383dd0472af499a6667736914cb4f5a9f58ce91 /src | |
parent | f9924c6636791410d89c2ec015e25de55449de12 (diff) | |
download | libsvgtiny-988e0d0819c7e6b068b1c1741a50b547f8414cf7.tar.gz libsvgtiny-988e0d0819c7e6b068b1c1741a50b547f8414cf7.tar.bz2 |
prevent division by zero for gradient with no points and add test
Diffstat (limited to 'src')
-rw-r--r-- | src/svgtiny_gradient.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/svgtiny_gradient.c b/src/svgtiny_gradient.c index f5984ea..c36df32 100644 --- a/src/svgtiny_gradient.c +++ b/src/svgtiny_gradient.c @@ -410,8 +410,7 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n, /* r, r0, r1 are distance along gradient vector */ gradient_norm_squared = gradient_dx * gradient_dx + gradient_dy * gradient_dy; - pts = svgtiny_list_create( - sizeof (struct grad_point)); + pts = svgtiny_list_create(sizeof (struct grad_point)); if (!pts) return svgtiny_OUT_OF_MEMORY; for (j = 0; j != n; ) { @@ -540,6 +539,13 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n, svgtiny_list_size(pts), min_pt, min_r); #endif + /* There must be at least a single point for the gradient */ + if (svgtiny_list_size(pts) == 0) { + svgtiny_list_free(pts); + + return svgtiny_OK; + } + /* render triangles */ stop_count = state->linear_gradient_stop_count; assert(2 <= stop_count); |