From edf5d45ee2b3b1fbd97ce68e0853ab98d88dee9a Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Fri, 21 Oct 2022 09:09:39 +0000
Subject: [PATCH] update to Fedora to version 35

---
 common/Dockerfile                        |  2 +-
 common/include/villas/memory_manager.hpp |  4 ++--
 common/include/villas/plugin.hpp         |  2 +-
 common/include/villas/utils.hpp          |  2 +-
 common/lib/log.cpp                       |  2 ++
 common/lib/memory_manager.cpp            |  8 ++++----
 common/lib/utils.cpp                     | 16 ++++++++++-----
 common/lib/uuid.cpp                      | 26 ++++++++++++++----------
 common/tests/unit/hist.cpp               |  2 +-
 9 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/common/Dockerfile b/common/Dockerfile
index b1f10275d..6310b4a0e 100644
--- a/common/Dockerfile
+++ b/common/Dockerfile
@@ -16,7 +16,7 @@
 #
 ###################################################################################
 
-FROM fedora:33
+FROM fedora:36
 
 LABEL \
 	org.label-schema.schema-version="1.0" \
diff --git a/common/include/villas/memory_manager.hpp b/common/include/villas/memory_manager.hpp
index 8337a7b1f..c5f3575e4 100644
--- a/common/include/villas/memory_manager.hpp
+++ b/common/include/villas/memory_manager.hpp
@@ -209,10 +209,10 @@ public:
 	findAddressSpace(const std::string &name);
 
 	std::list<AddressSpaceId>
-	findPath(AddressSpaceId fromAddrSpaceId, AddressSpaceId toAddrSpaceId);
+	findPath(const AddressSpaceId &fromAddrSpaceId, const AddressSpaceId &toAddrSpaceId);
 
 	MemoryTranslation
-	getTranslation(AddressSpaceId fromAddrSpaceId, AddressSpaceId toAddrSpaceId);
+	getTranslation(const AddressSpaceId &fromAddrSpaceId, const AddressSpaceId &toAddrSpaceId);
 
 	// cppcheck-suppress passedByValue
 	MemoryTranslation getTranslationFromProcess(AddressSpaceId foreignAddrSpaceId)
diff --git a/common/include/villas/plugin.hpp b/common/include/villas/plugin.hpp
index d87291b95..2cf386eb1 100644
--- a/common/include/villas/plugin.hpp
+++ b/common/include/villas/plugin.hpp
@@ -169,7 +169,7 @@ public:
 	}
 };
 
-template<typename T = Plugin>
+template<typename T>
 void
 Registry::dump()
 {
diff --git a/common/include/villas/utils.hpp b/common/include/villas/utils.hpp
index 49c422258..132cb651e 100644
--- a/common/include/villas/utils.hpp
+++ b/common/include/villas/utils.hpp
@@ -111,7 +111,7 @@ namespace villas {
 namespace utils {
 
 std::vector<std::string>
-tokenize(std::string s, std::string delimiter);
+tokenize(std::string s, const std::string &delimiter);
 
 template<typename T>
 void
diff --git a/common/lib/log.cpp b/common/lib/log.cpp
index 06bc8c78d..bbb4855e6 100644
--- a/common/lib/log.cpp
+++ b/common/lib/log.cpp
@@ -152,6 +152,8 @@ void Log::parse(json_t *json)
 
 		size_t i;
 		json_t *json_expression;
+
+		// cppcheck-suppress unknownMacro
 		json_array_foreach(json_expressions, i, json_expression)
 			expressions.emplace_back(json_expression);
 	}
diff --git a/common/lib/memory_manager.cpp b/common/lib/memory_manager.cpp
index 052ef5ba0..81dfc6f15 100644
--- a/common/lib/memory_manager.cpp
+++ b/common/lib/memory_manager.cpp
@@ -85,8 +85,8 @@ MemoryManager::findAddressSpace(const std::string &name)
 }
 
 std::list<MemoryManager::AddressSpaceId>
-MemoryManager::findPath(MemoryManager::AddressSpaceId fromAddrSpaceId,
-                        MemoryManager::AddressSpaceId toAddrSpaceId)
+MemoryManager::findPath(const MemoryManager::AddressSpaceId &fromAddrSpaceId,
+                        const MemoryManager::AddressSpaceId &toAddrSpaceId)
 {
 	std::list<AddressSpaceId> path;
 
@@ -112,8 +112,8 @@ MemoryManager::findPath(MemoryManager::AddressSpaceId fromAddrSpaceId,
 }
 
 MemoryTranslation
-MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId,
-                              MemoryManager::AddressSpaceId toAddrSpaceId)
+MemoryManager::getTranslation(const MemoryManager::AddressSpaceId &fromAddrSpaceId,
+                              const MemoryManager::AddressSpaceId &toAddrSpaceId)
 {
 	// Find a path through the memory graph
 	MemoryGraph::Path path;
diff --git a/common/lib/utils.cpp b/common/lib/utils.cpp
index 0110e17e9..ecbc1036f 100644
--- a/common/lib/utils.cpp
+++ b/common/lib/utils.cpp
@@ -38,7 +38,7 @@ static pthread_t main_thread;
 namespace villas {
 namespace utils {
 
-std::vector<std::string> tokenize(std::string s, std::string delimiter)
+std::vector<std::string> tokenize(std::string s, const std::string &delimiter)
 {
 	std::vector<std::string> tokens;
 
@@ -318,7 +318,7 @@ int log2i(long long x) {
 
 int sha1sum(FILE *f, unsigned char *sha1)
 {
-	SHA_CTX c;
+	int ret;
 	char buf[512];
 	ssize_t bytes;
 	long seek;
@@ -326,18 +326,24 @@ int sha1sum(FILE *f, unsigned char *sha1)
 	seek = ftell(f);
 	fseek(f, 0, SEEK_SET);
 
-	SHA1_Init(&c);
+	EVP_MD_CTX *c = EVP_MD_CTX_new();
+
+	ret = EVP_DigestInit(c, EVP_sha1());
+	if (!ret)
+		return -1;
 
 	bytes = fread(buf, 1, 512, f);
 	while (bytes > 0) {
-		SHA1_Update(&c, buf, bytes);
+		EVP_DigestUpdate(c, buf, bytes);
 		bytes = fread(buf, 1, 512, f);
 	}
 
-	SHA1_Final(sha1, &c);
+	EVP_DigestFinal(c, sha1, nullptr);
 
 	fseek(f, seek, SEEK_SET);
 
+	EVP_MD_CTX_free(c);
+
 	return 0;
 }
 
diff --git a/common/lib/uuid.cpp b/common/lib/uuid.cpp
index 0d7750c65..c01f4e82a 100644
--- a/common/lib/uuid.cpp
+++ b/common/lib/uuid.cpp
@@ -5,7 +5,7 @@
  * @license Apache License 2.0
  *********************************************************************************/
 
-#include <openssl/md5.h>
+#include <openssl/evp.h>
 
 #include <villas/uuid.hpp>
 
@@ -14,52 +14,56 @@ using namespace villas::uuid;
 int villas::uuid::generateFromString(uuid_t out, const std::string &data, const std::string &ns)
 {
 	int ret;
-	MD5_CTX c;
+	EVP_MD_CTX *c = EVP_MD_CTX_new();
 
-	ret = MD5_Init(&c);
+	ret = EVP_DigestInit(c, EVP_md5());
 	if (!ret)
 		return -1;
 
 	/* Namespace */
-	ret = MD5_Update(&c, (unsigned char *) ns.c_str(), ns.size());
+	ret = EVP_DigestUpdate(c, (unsigned char *) ns.c_str(), ns.size());
 	if (!ret)
 		return -1;
 
 	/* Data */
-	ret = MD5_Update(&c, (unsigned char *) data.c_str(), data.size());
+	ret = EVP_DigestUpdate(c, (unsigned char *) data.c_str(), data.size());
 	if (!ret)
 		return -1;
 
-	ret = MD5_Final((unsigned char *) out, &c);
+	ret = EVP_DigestFinal(c, (unsigned char *) out, nullptr);
 	if (!ret)
 		return -1;
 
+	EVP_MD_CTX_free(c);
+
 	return 0;
 }
 
 int villas::uuid::generateFromString(uuid_t out, const std::string &data, const uuid_t ns)
 {
 	int ret;
-	MD5_CTX c;
+	EVP_MD_CTX *c = EVP_MD_CTX_new();
 
-	ret = MD5_Init(&c);
+	ret = EVP_DigestInit(c, EVP_md5());
 	if (!ret)
 		return -1;
 
 	/* Namespace */
-	ret = MD5_Update(&c, (unsigned char *) ns, 16);
+	ret = EVP_DigestUpdate(c, (unsigned char *) ns, 16);
 	if (!ret)
 		return -1;
 
 	/* Data */
-	ret = MD5_Update(&c, (unsigned char *) data.c_str(), data.size());
+	ret = EVP_DigestUpdate(c, (unsigned char *) data.c_str(), data.size());
 	if (!ret)
 		return -1;
 
-	ret = MD5_Final((unsigned char *) out, &c);
+	ret = EVP_DigestFinal(c, (unsigned char *) out, nullptr);
 	if (!ret)
 		return -1;
 
+	EVP_MD_CTX_free(c);
+
 	return 0;
 }
 
diff --git a/common/tests/unit/hist.cpp b/common/tests/unit/hist.cpp
index 6dfa07bf8..0de366f52 100644
--- a/common/tests/unit/hist.cpp
+++ b/common/tests/unit/hist.cpp
@@ -27,6 +27,6 @@ Test(hist, simple) {
 		h.put(td);
 
 	cr_assert_float_eq(h.getMean(), 5.5, 1e-6, "Mean is %lf", h.getMean());
-	cr_assert_float_eq(h.getVar(), 9.1666, 1e-3,);
+	cr_assert_float_eq(h.getVar(), 9.1666, 1e-3);
 	cr_assert_float_eq(h.getStddev(), 3.027650, 1e-6);
 }