Repository: GuillaumeGomez/rust-GSL (language: rust)

Issue:
legendre_Pl_array and legendre_Pl_deriv_array are broken
The [gsl docs](https://www.gnu.org/software/gsl/doc/html/specfunc.html?highlight=legendre#c.gsl_sf_legendre_Pl_array) state:
> These functions compute arrays of Legendre polynomials P_l(x) and derivatives dP_l(x)/dx for l = 0, \dots, lmax and |x| \le 1.

That is the parameter `l` is not the size of the array for the results. Thus the following is wrong:
https://github.com/GuillaumeGomez/rust-GSL/blob/c21148fc63946dfa8a19e9894d830fd6de28ce33/src/legendre.rs#L75

Like that gsl tries to write to the address after the last array element resulting in undefined behavior.


Discussion / hints:

Fix patch:
diff --git a/src/legendre.rs b/src/legendre.rs
index a45de78d..02236e21 100644
--- a/src/legendre.rs
+++ b/src/legendre.rs
@@ -70,10 +70,8 @@ pub mod polynomials {
 
     /// This function computes arrays of Legendre polynomials P_l(x) and derivatives dP_l(x)/dx, for l = 0, \dots, lmax, |x| <= 1
     #[doc(alias = "gsl_sf_legendre_Pl_array")]
-    pub fn legendre_Pl_array(x: f64, result_array: &mut [f64]) -> Result<(), Value> {
-        let ret = unsafe {
-            sys::gsl_sf_legendre_Pl_array(result_array.len() as i32, x, result_array.as_mut_ptr())
-        };
+    pub fn legendre_Pl_array(lmax: usize, x: f64, result_array: &mut [f64]) -> Result<(), Value> {
+        let ret = unsafe { sys::gsl_sf_legendre_Pl_array(lmax as _, x, result_array.as_mut_ptr()) };
         result_handler!(ret, ())
     }
 


Test patch: