Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/__pchip_deriv__.cc @ 14462:af552038cc52 stable
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.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 14 Mar 2012 13:34:59 -0400 |
parents | 72c96de7a403 |
children | 60e5cf354d80 |
comparison
equal
deleted
inserted
replaced
14452:721be41ea988 | 14462:af552038cc52 |
---|---|
67 { | 67 { |
68 FloatColumnVector xvec (args(0).float_vector_value ()); | 68 FloatColumnVector xvec (args(0).float_vector_value ()); |
69 FloatMatrix ymat (args(1).float_matrix_value ()); | 69 FloatMatrix ymat (args(1).float_matrix_value ()); |
70 | 70 |
71 octave_idx_type nx = xvec.length (); | 71 octave_idx_type nx = xvec.length (); |
72 | |
73 if (nx < 2) | |
74 { | |
75 error ("__pchip_deriv__: X must be at least of length 2"); | |
76 return retval; | |
77 } | |
78 | |
72 octave_idx_type nyr = ymat.rows (); | 79 octave_idx_type nyr = ymat.rows (); |
73 octave_idx_type nyc = ymat.columns (); | 80 octave_idx_type nyc = ymat.columns (); |
74 | 81 |
75 if (nx != (rows ? nyc : nyr)) | 82 if (nx != (rows ? nyc : nyr)) |
76 { | 83 { |
107 { | 114 { |
108 ColumnVector xvec (args(0).vector_value ()); | 115 ColumnVector xvec (args(0).vector_value ()); |
109 Matrix ymat (args(1).matrix_value ()); | 116 Matrix ymat (args(1).matrix_value ()); |
110 | 117 |
111 octave_idx_type nx = xvec.length (); | 118 octave_idx_type nx = xvec.length (); |
119 | |
120 if (nx < 2) | |
121 { | |
122 error ("__pchip_deriv__: X must be at least of length 2"); | |
123 return retval; | |
124 } | |
125 | |
112 octave_idx_type nyr = ymat.rows (); | 126 octave_idx_type nyr = ymat.rows (); |
113 octave_idx_type nyc = ymat.columns (); | 127 octave_idx_type nyc = ymat.columns (); |
114 | 128 |
115 if (nx != (rows ? nyc : nyr)) | 129 if (nx != (rows ? nyc : nyr)) |
116 { | 130 { |