From 65cd09caf21b19171e7793a0bb8765b8aa383835 Mon Sep 17 00:00:00 2001 From: NIKEA-SOFT Date: Mon, 9 May 2022 21:26:45 +0300 Subject: [PATCH] Fix: Codacy, pf_map cast and copy cm_parameter --- common/aicore/cm.cpp | 2 +- common/aicore/cm.h | 7 +++++++ common/aicore/path_finding.cpp | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/common/aicore/cm.cpp b/common/aicore/cm.cpp index 2dddf90318..732e675aff 100644 --- a/common/aicore/cm.cpp +++ b/common/aicore/cm.cpp @@ -2133,7 +2133,7 @@ bool operator==(const struct cm_parameter &p1, const struct cm_parameter &p2) void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src) { - memcpy(dest, src, sizeof(struct cm_parameter)); + *dest = *src; } /** diff --git a/common/aicore/cm.h b/common/aicore/cm.h index b470eeef79..38fa3ea700 100644 --- a/common/aicore/cm.h +++ b/common/aicore/cm.h @@ -22,6 +22,13 @@ struct cm_parameter { int factor[O_LAST]; int happy_factor; + + /** + * @brief Copy assignment operator + * @param other Object being copied + * @return Reference to *this + */ + cm_parameter &operator=(const cm_parameter &other) = default; }; // A result which can examined. diff --git a/common/aicore/path_finding.cpp b/common/aicore/path_finding.cpp index c586130d44..a8e9b48af0 100644 --- a/common/aicore/path_finding.cpp +++ b/common/aicore/path_finding.cpp @@ -95,8 +95,22 @@ struct pf_map { struct pf_parameter params; // Initial parameters. }; -// Down-cast macro. -#define PF_MAP(pfm) ((struct pf_map *) (pfm)) +/** + * Casts to `pf_map` + * + * \fixme Capitalized because this used to be a macro. + */ +pf_map *PF_MAP(void *x) { return reinterpret_cast(x); } + +/** + * Casts to `pf_map` + * + * \fixme Capitalized because this used to be a macro. + */ +const pf_map *PF_MAP(const void *x) +{ + return reinterpret_cast(x); +} // ========================== Common functions ===========================