From 0c5d106f7aff399d128ab2b4a1f070385a5272f8 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 25 Oct 2024 19:36:03 +0200 Subject: [PATCH] memcpy --- src/swig/nlopt-python.i | 6 ++++-- test/cpp_functor.cxx | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/swig/nlopt-python.i b/src/swig/nlopt-python.i index b5cf55e1..30c7ccb0 100644 --- a/src/swig/nlopt-python.i +++ b/src/swig/nlopt-python.i @@ -124,8 +124,10 @@ __version__ = str(_nlopt.version_major())+'.'+str(_nlopt.version_minor())+'.'+st { npy_intp sz = $1.size(); $result = PyArray_SimpleNew(1, &sz, NPY_DOUBLE); - std::memcpy(array_data($result), $1.empty() ? NULL : &$1[0], - sizeof(double) * sz); + if (!$1.empty()) + { + std::memcpy(array_data($result), &$1[0], sizeof(double) * sz); + } } ////////////////////////////////////////////////////////////////////////////// diff --git a/test/cpp_functor.cxx b/test/cpp_functor.cxx index 47168368..0ec8e423 100644 --- a/test/cpp_functor.cxx +++ b/test/cpp_functor.cxx @@ -100,7 +100,7 @@ class LinearRegression { LinearRegression(QuadraticForm quadratic_form_) : quadratic_form(std::move(quadratic_form_)) {} - double operator()(unsigned n, const double* x, double* grad) const + double operator()(unsigned /*n*/, const double* x, double* grad) const { const double result = quadratic_form.compute_form(x); if (!!grad) {