From 86311c357ee96b6bbfd0d9d60a40fae04d8ec1b7 Mon Sep 17 00:00:00 2001 From: alixdamman Date: Wed, 25 Oct 2023 15:20:07 +0200 Subject: [PATCH] C++ API: (Equation) made create_equation_deep_copy() to call clec_deep_copy() instead of using memcpy for the clec attribute of the struct EQ --- cpp_api/objects/equation.cpp | 7 +++++-- cpp_api/objects/equation.h | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cpp_api/objects/equation.cpp b/cpp_api/objects/equation.cpp index 85b210af5..b7fee4b8b 100644 --- a/cpp_api/objects/equation.cpp +++ b/cpp_api/objects/equation.cpp @@ -5,11 +5,14 @@ EQ* create_equation_deep_copy(EQ* original_equation) { EQ* copy_eq = (EQ*) SW_nalloc(sizeof(EQ)); + // NOTE : we do not use memcpy() because memcpy() actually makes + // a shallow copy of a struct instead of a deep copy + copy_eq->clec = clec_deep_copy(original_equation->clec); copy_eq->lec = copy_char_array(original_equation->lec); - copy_eq->clec = (CLEC*) SW_nalloc(sizeof(CLEC)); - memcpy(copy_eq->clec, original_equation->clec, sizeof(CLEC)); copy_eq->solved = original_equation->solved; copy_eq->method = original_equation->method; + // NOTE : we can use memcpy() on SAMPLE because SAMPLE does + // not contain attributes which are pointers memcpy(©_eq->smpl, &original_equation->smpl, sizeof(SAMPLE)); copy_eq->cmt = copy_char_array(original_equation->cmt); copy_eq->blk = copy_char_array(original_equation->blk); diff --git a/cpp_api/objects/equation.h b/cpp_api/objects/equation.h index d008323dc..0769187e0 100644 --- a/cpp_api/objects/equation.h +++ b/cpp_api/objects/equation.h @@ -3,6 +3,8 @@ #include "utils/utils.h" #include "time/period.h" #include "time/sample.h" +#include "lec/lec.h" + #include #include