Hi,

I noticed a few issues running make check on the latest source (b6c4b6e, 
obtained via savannah git clone, compiled using gcc 12.2.0 for both O2 and O3, 
on linux x86_64):


* cspline test segfaults when there are only two data points, because it tries 
to solve a 0x0 linear system and ultimately write alpha[0] = diag[0] inside 
solve_tridiag

* bsd_initialize and libc5_initialize can have signed integer overflow, 
reported in the rng test suite by ubsan

* test suites for matrix and vector did not properly free all memory, reported 
by asan


I am attaching a patch that I believe addresses the issues.  (I have not 
submitted a patch before, so if I did something wrong, just let me know.)


Ryan
diff --git interpolation/cspline.c interpolation/cspline.c
index c901c86..55d6efb 100644
--- interpolation/cspline.c
+++ interpolation/cspline.c
@@ -155,7 +155,7 @@ cspline_init (void * vstate, const double xa[], const double ya[], size_t size)
     {
       state->c[1] = state->g[0] / state->diag[0];
     }
-  else
+  else if (sys_size > 1)
     {
       gsl_vector_view g_vec = gsl_vector_view_array(state->g, sys_size);
       gsl_vector_view diag_vec = gsl_vector_view_array(state->diag, sys_size);
diff --git matrix/test_complex_source.c matrix/test_complex_source.c
index 9d060d4..1e96914 100644
--- matrix/test_complex_source.c
+++ matrix/test_complex_source.c
@@ -747,6 +747,7 @@ FUNCTION (test, ops) (const size_t P, const size_t Q)
       }
 
     gsl_test (status, NAME (gsl_matrix) "_scale_rows[%zu,%zu]", P, Q);
+    FUNCTION (gsl_vector, free) (v);
   }
 
   {
@@ -784,6 +785,7 @@ FUNCTION (test, ops) (const size_t P, const size_t Q)
       }
 
     gsl_test (status, NAME (gsl_matrix) "_scale_columns[%zu,%zu]", P, Q);
+    FUNCTION (gsl_vector, free) (v);
   }
 
   {
diff --git rng/random.c rng/random.c
index b292eb3..d652265 100644
--- rng/random.c
+++ rng/random.c
@@ -39,7 +39,7 @@
   
  */
 
-static inline long int random_get (int * i, int * j, int n, long int * x);
+static inline unsigned long int random_get (int * i, int * j, int n, unsigned long int * x);
 
 static inline unsigned long int random8_get (void *vstate);
 static inline unsigned long int random32_get (void *vstate);
@@ -71,41 +71,41 @@ static void random64_bsd_set (void *state, unsigned long int s);
 static void random128_bsd_set (void *state, unsigned long int s);
 static void random256_bsd_set (void *state, unsigned long int s);
 
-static void bsd_initialize (long int * x, int n, unsigned long int s);
-static void libc5_initialize (long int * x, int n, unsigned long int s);
-static void glibc2_initialize (long int * x, int n, unsigned long int s);
+static void bsd_initialize (unsigned long int * x, int n, unsigned long int s);
+static void libc5_initialize (unsigned long int * x, int n, unsigned long int s);
+static void glibc2_initialize (unsigned long int * x, int n, unsigned long int s);
 
 typedef struct
   {
-    long int x;
+    unsigned long int x;
   }
 random8_state_t;
 
 typedef struct
   {
     int i, j;
-    long int x[7];
+    unsigned long int x[7];
   }
 random32_state_t;
 
 typedef struct
   {
     int i, j;
-    long int x[15];
+    unsigned long int x[15];
   }
 random64_state_t;
 
 typedef struct
   {
     int i, j;
-    long int x[31];
+    unsigned long int x[31];
   }
 random128_state_t;
 
 typedef struct
   {
     int i, j;
-    long int x[63];
+    unsigned long int x[63];
   }
 random256_state_t;
 
@@ -118,10 +118,10 @@ random8_get (void *vstate)
   return state->x;
 }
 
-static inline long int
-random_get (int * i, int * j, int n, long int * x)
+static inline unsigned long int
+random_get (int * i, int * j, int n, unsigned long int * x)
 {
-  long int k ;
+  unsigned long int k ;
 
   x[*i] += x[*j] ;
   k = (x[*i] >> 1) & 0x7FFFFFFF ;
@@ -149,7 +149,7 @@ static inline unsigned long int
 random64_get (void *vstate)
 {
   random64_state_t *state = (random64_state_t *) vstate;
-  long int k = random_get (&state->i, &state->j, 15, state->x) ; 
+  unsigned long int k = random_get (&state->i, &state->j, 15, state->x) ; 
   return k ;
 }
 
@@ -165,7 +165,7 @@ static inline unsigned long int
 random256_get (void *vstate)
 {
   random256_state_t *state = (random256_state_t *) vstate;
-  long int k = random_get (&state->i, &state->j, 63, state->x) ; 
+  unsigned long int k = random_get (&state->i, &state->j, 63, state->x) ; 
   return k ;
 }
 
@@ -271,7 +271,7 @@ random256_bsd_set (void *vstate, unsigned long int s)
 }
 
 static void 
-bsd_initialize (long int * x, int n, unsigned long int s)
+bsd_initialize (unsigned long int * x, int n, unsigned long int s)
 {
   int i; 
 
@@ -285,7 +285,7 @@ bsd_initialize (long int * x, int n, unsigned long int s)
 }
 
 static void 
-libc5_initialize (long int * x, int n, unsigned long int s)
+libc5_initialize (unsigned long int * x, int n, unsigned long int s)
 {
   int i; 
 
@@ -299,7 +299,7 @@ libc5_initialize (long int * x, int n, unsigned long int s)
 }
 
 static void 
-glibc2_initialize (long int * x, int n, unsigned long int s)
+glibc2_initialize (unsigned long int * x, int n, unsigned long int s)
 {
   int i; 
 
diff --git vector/test_complex_source.c vector/test_complex_source.c
index 0ac1d29..8cf1b95 100644
--- vector/test_complex_source.c
+++ vector/test_complex_source.c
@@ -731,6 +731,7 @@ FUNCTION (test, ops) (size_t stride1, size_t stride2, size_t N)
   FUNCTION(gsl_vector, free) (a);
   FUNCTION(gsl_vector, free) (b);
   FUNCTION(gsl_vector, free) (v);
+  REAL_FUNCTION(gsl_vector, free) (c);
 }
 
 void 

Reply via email to