# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1331746499 14400 # Node ID af552038cc520311ab60aba66c2bb27dd3a5a856 # Parent 721be41ea98875e04152570e7862dcf3a6610538 Fix segfault in pchip when input array is too small (bug #35835). * __pchip_deriv__.cc (F__pchip_deriv__): Error out if x isn't at least of length 2. * pchip.m: Write two tests for this. diff --git a/scripts/polynomial/pchip.m b/scripts/polynomial/pchip.m --- a/scripts/polynomial/pchip.m +++ b/scripts/polynomial/pchip.m @@ -167,3 +167,6 @@ %!assert(squeeze(yi1(1,2,:)),[1/sqrt(2); 0; -1/sqrt(2);-1],1e-14); %!assert(size(yi2),[3,2,5,4]); %!assert(squeeze(yi2(1,2,3,:)),[1/sqrt(2); 0; -1/sqrt(2);-1],1e-14); + +%!error (pchip (1,2)); +%!error (pchip (1,2,3)); diff --git a/src/DLD-FUNCTIONS/__pchip_deriv__.cc b/src/DLD-FUNCTIONS/__pchip_deriv__.cc --- a/src/DLD-FUNCTIONS/__pchip_deriv__.cc +++ b/src/DLD-FUNCTIONS/__pchip_deriv__.cc @@ -69,6 +69,13 @@ FloatMatrix ymat (args(1).float_matrix_value ()); octave_idx_type nx = xvec.length (); + + if (nx < 2) + { + error ("__pchip_deriv__: X must be at least of length 2"); + return retval; + } + octave_idx_type nyr = ymat.rows (); octave_idx_type nyc = ymat.columns (); @@ -109,6 +116,13 @@ Matrix ymat (args(1).matrix_value ()); octave_idx_type nx = xvec.length (); + + if (nx < 2) + { + error ("__pchip_deriv__: X must be at least of length 2"); + return retval; + } + octave_idx_type nyr = ymat.rows (); octave_idx_type nyc = ymat.columns ();