From b68c55fec023dd13a98eab357dfc1acafb69e940 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 5 Apr 2014 09:40:24 +0200 Subject: [PATCH] Bugfix: the Y coordinate of Point config fields was not correctly validated and lead to a crash when entering non-numeric values. Includes regression test. #1906 --- xs/src/Point.cpp | 2 +- xs/t/15_config.t | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/xs/src/Point.cpp b/xs/src/Point.cpp index a6c844054..21ec83900 100644 --- a/xs/src/Point.cpp +++ b/xs/src/Point.cpp @@ -207,7 +207,7 @@ Pointf::from_SV(SV* point_sv) AV* point_av = (AV*)SvRV(point_sv); SV* sv_x = *av_fetch(point_av, 0, 0); SV* sv_y = *av_fetch(point_av, 1, 0); - if (!looks_like_number(sv_x) || !looks_like_number(sv_x)) return false; + if (!looks_like_number(sv_x) || !looks_like_number(sv_y)) return false; this->x = SvNV(sv_x); this->y = SvNV(sv_y); diff --git a/xs/t/15_config.t b/xs/t/15_config.t index 347e68edf..8200de246 100644 --- a/xs/t/15_config.t +++ b/xs/t/15_config.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 94; +use Test::More tests => 100; foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) { $config->set('layer_height', 0.3); @@ -33,11 +33,13 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) { ok abs($config->get_abs_value('first_layer_height') - 0.15) < 1e-4, 'set/get relative floatOrPercent'; is $config->serialize('first_layer_height'), '50%', 'serialize relative floatOrPercent'; - $config->set('print_center', [50,80]); + ok $config->set('print_center', [50,80]), 'valid point coordinates'; is_deeply $config->get('print_center'), [50,80], 'set/get point'; is $config->serialize('print_center'), '50,80', 'serialize point'; $config->set_deserialize('print_center', '20,10'); is_deeply $config->get('print_center'), [20,10], 'deserialize point'; + ok !$config->set('print_center', ['t',80]), 'invalid point X'; + ok !$config->set('print_center', [50,'t']), 'invalid point Y'; $config->set('use_relative_e_distances', 1); is $config->get('use_relative_e_distances'), 1, 'set/get bool';