Mercurial > octave-nkf
comparison libinterp/dldfcn/__voronoi__.cc @ 18077:ac74b0c4c564 stable
avoid overflow when passing problem dimensions to qhull with --enable-64
* __delaunayn__.cc, __voronoi__.cc, convhulln.cc
(octave_qhull_dims_ok): New function. Use it to avoid overflowing
the range of integer values used in Qhull when Octave uses 64-bit
integer indexing.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 03 Dec 2013 21:39:39 -0500 |
parents | 175b392e91fe |
children | 65554f5847ac 446c46af4b42 |
comparison
equal
deleted
inserted
replaced
18075:24759ac2b8cb | 18077:ac74b0c4c564 |
---|---|
55 | 55 |
56 static void | 56 static void |
57 close_fcn (FILE *f) | 57 close_fcn (FILE *f) |
58 { | 58 { |
59 gnulib::fclose (f); | 59 gnulib::fclose (f); |
60 } | |
61 | |
62 static bool | |
63 octave_qhull_dims_ok (octave_idx_type dim, octave_idx_type n, const char *who) | |
64 { | |
65 if (sizeof (octave_idx_type) > sizeof (int)) | |
66 { | |
67 int maxval = std::numeric_limits<int>::max (); | |
68 | |
69 if (dim > maxval || n > maxval) | |
70 { | |
71 error ("%s: dimension too large for Qhull", who); | |
72 return false; | |
73 } | |
74 } | |
75 | |
76 return true; | |
60 } | 77 } |
61 | 78 |
62 DEFUN_DLD (__voronoi__, args, , | 79 DEFUN_DLD (__voronoi__, args, , |
63 "-*- texinfo -*-\n\ | 80 "-*- texinfo -*-\n\ |
64 @deftypefn {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts})\n\ | 81 @deftypefn {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts})\n\ |
83 } | 100 } |
84 | 101 |
85 Matrix points = args(1).matrix_value (); | 102 Matrix points = args(1).matrix_value (); |
86 const octave_idx_type dim = points.columns (); | 103 const octave_idx_type dim = points.columns (); |
87 const octave_idx_type num_points = points.rows (); | 104 const octave_idx_type num_points = points.rows (); |
105 | |
106 if (! octave_qhull_dims_ok (dim, num_points, "__voronoi__")) | |
107 return retval; | |
88 | 108 |
89 points = points.transpose (); | 109 points = points.transpose (); |
90 | 110 |
91 std::string options; | 111 std::string options; |
92 | 112 |