From 86786232b382aa092ae901b29745783218217554 Mon Sep 17 00:00:00 2001
From: Joris Vaillant <joris.vaillant@inria.fr>
Date: Fri, 20 Dec 2024 22:01:54 +0100
Subject: [PATCH] tests: Allocate buffer on the heap instead of the stack

---
 tests/load_problem.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tests/load_problem.h b/tests/load_problem.h
index e202afb..fc9567f 100644
--- a/tests/load_problem.h
+++ b/tests/load_problem.h
@@ -19,7 +19,7 @@
 namespace ndcurves {
 
 typedef Eigen::Vector3d point_t;
-typedef std::vector<point_t, Eigen::aligned_allocator<point_t> > t_point_t;
+typedef std::vector<point_t, Eigen::aligned_allocator<point_t>> t_point_t;
 typedef Eigen::VectorXd pointX_t;
 typedef std::pair<double, pointX_t> Waypoint;
 typedef std::vector<Waypoint> T_Waypoint;
@@ -41,9 +41,10 @@ typedef quadratic_problem<point_t, double> problem_t;
 
 #define MAXBUFSIZE ((int)1e6)
 
-Eigen::MatrixXd readMatrix(std::ifstream& infile) {
+Eigen::MatrixXd readMatrix(std::ifstream &infile) {
   int cols = 0, rows = 0;
-  double buff[MAXBUFSIZE];
+  std::vector<double> buff;
+  buff.resize(MAXBUFSIZE);
 
   // Read numbers from file into buffer.
   // ifstream infile;
@@ -54,7 +55,8 @@ Eigen::MatrixXd readMatrix(std::ifstream& infile) {
 
     int temp_cols = 0;
     std::stringstream stream(line);
-    while (!stream.eof()) stream >> buff[cols * rows + temp_cols++];
+    while (!stream.eof())
+      stream >> buff[static_cast<size_t>(cols * rows + temp_cols++)];
 
     if (temp_cols == 0) continue;
 
@@ -73,7 +75,7 @@ Eigen::MatrixXd readMatrix(std::ifstream& infile) {
   return result;
 }
 
-problem_definition_t loadproblem(const std::string& filename) {
+problem_definition_t loadproblem(const std::string &filename) {
   problem_definition_t pDef(3);
   std::ifstream in(filename.c_str());
   if (!in.is_open()) throw std::runtime_error("cant open filename");
-- 
GitLab