diff --git a/common/.gitlab-ci.yml b/common/.gitlab-ci.yml index 59fc15271..5bcab0e10 100644 --- a/common/.gitlab-ci.yml +++ b/common/.gitlab-ci.yml @@ -59,6 +59,7 @@ test:cppcheck: --quiet --inline-suppr --enable=warning,performance,portability,information,missingInclude + --suppress=noValidConfiguration --std=c++11 -I include lib/ diff --git a/common/include/villas/buffer.hpp b/common/include/villas/buffer.hpp index 0fc4fa5f1..98d24f579 100644 --- a/common/include/villas/buffer.hpp +++ b/common/include/villas/buffer.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include @@ -34,14 +35,10 @@ namespace villas { class Buffer { public: - char *buf; - size_t len; - size_t size; + std::vector buf; Buffer(size_t size); - ~Buffer(); - void clear(); int append(const char *data, size_t len); diff --git a/common/include/villas/dsp/pid.hpp b/common/include/villas/dsp/pid.hpp index 4c0cf8c07..539e184b0 100644 --- a/common/include/villas/dsp/pid.hpp +++ b/common/include/villas/dsp/pid.hpp @@ -30,27 +30,27 @@ class PID { protected: double dt; - double max; - double min; - double Kp; - double Kd; - double Ki; - double pre_error; - double integral; + double max; + double min; + double Kp; + double Kd; + double Ki; + double pre_error; + double integral; public: - /** + /** * Kp - proportional gain - * Ki - Integral gain - * Kd - derivative gain - * dt - loop interval time - * max - maximum value of manipulated variable - * min - minimum value of manipulated variable + * Ki - Integral gain + * Kd - derivative gain + * dt - loop interval time + * max - maximum value of manipulated variable + * min - minimum value of manipulated variable */ - PID(double _dt, double _max, double _min, double _Kp, double _Kd, double _Ki); + PID(double _dt, double _max, double _min, double _Kp, double _Kd, double _Ki); - /** Returns the manipulated variable given a setpoint and current process value */ - double calculate(double setpoint, double pv); + /** Returns the manipulated variable given a setpoint and current process value */ + double calculate(double setpoint, double pv); }; } /* namespace dsp */ diff --git a/common/include/villas/kernel/pci.hpp b/common/include/villas/kernel/pci.hpp index 3cea72473..91ce842c8 100644 --- a/common/include/villas/kernel/pci.hpp +++ b/common/include/villas/kernel/pci.hpp @@ -50,9 +50,9 @@ public: bool operator==(const Id &i); - int vendor; - int device; - int class_code; + unsigned int vendor; + unsigned int device; + unsigned int class_code; }; class Slot { @@ -69,10 +69,10 @@ public: bool operator==(const Slot &s); - int domain; - int bus; - int device; - int function; + unsigned int domain; + unsigned int bus; + unsigned int device; + unsigned int function; }; struct Region { diff --git a/common/include/villas/kernel/vfio.hpp b/common/include/villas/kernel/vfio.hpp index f73c9136b..8589c692f 100644 --- a/common/include/villas/kernel/vfio.hpp +++ b/common/include/villas/kernel/vfio.hpp @@ -45,7 +45,11 @@ class Device { friend class Container; public: Device(const std::string &name, Group &group) : - name(name), group(group) {} + name(name), + fd(-1), + pci_device(nullptr), + group(group) + { } ~Device(); @@ -97,7 +101,11 @@ class Group { friend class Container; friend Device; private: - Group(int index) : fd(-1), index(index) {} + Group(int index) : + fd(-1), + index(index), + container(nullptr) + { } public: ~Group(); diff --git a/common/include/villas/memory.hpp b/common/include/villas/memory.hpp index 389c43483..fc44fc801 100644 --- a/common/include/villas/memory.hpp +++ b/common/include/villas/memory.hpp @@ -133,7 +133,7 @@ class BaseAllocator { public: /// memoryAddrSpaceId: memory that is managed by this allocator BaseAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId) : - memoryAddrSpaceId(memoryAddrSpaceId) + memoryAddrSpaceId(memoryAddrSpaceId) { // CRTP derivedAlloc = static_cast(this); @@ -150,9 +150,11 @@ public: } BaseAllocator(std::unique_ptr mem) : - BaseAllocator(mem->getAddrSpaceId()) + BaseAllocator(mem->getAddrSpaceId()) { + // cppcheck-suppress useInitializationList memoryBlock = std::move(mem); + derivedAlloc = nullptr; } virtual std::unique_ptr diff --git a/common/include/villas/memory_manager.hpp b/common/include/villas/memory_manager.hpp index 32578c4b1..e9a365b53 100644 --- a/common/include/villas/memory_manager.hpp +++ b/common/include/villas/memory_manager.hpp @@ -51,7 +51,10 @@ public: * @param size Size of "memory window" */ MemoryTranslation(uintptr_t src, uintptr_t dst, size_t size) : - src(src), dst(dst), size(size) {} + src(src), + dst(dst), + size(size) + { } uintptr_t getLocalAddr(uintptr_t addrInForeignAddrSpace) const; @@ -96,10 +99,9 @@ class MemoryManager { private: // This is a singleton, so private constructor ... MemoryManager() : - memoryGraph("memory:graph") + memoryGraph("memory:graph"), + logger(logging.get("memory:manager")) { - logger = logging.get("memory:manager"); - pathCheckFunc = [&](const MemoryGraph::Path &path) { return this->pathCheck(path); }; diff --git a/common/lib/advio.cpp b/common/lib/advio.cpp index d3be3bb5c..5c757dce6 100644 --- a/common/lib/advio.cpp +++ b/common/lib/advio.cpp @@ -96,7 +96,7 @@ static char * advio_human_time(double t, char *buf, size_t len) const char *units[] = { "secs", "mins", "hrs", "days", "weeks", "months", "years" }; int divs[] = { 60, 60, 24, 7, 4, 12 }; - while (t > divs[i] && i < ARRAY_LEN(divs)) { + while (i < ARRAY_LEN(divs) && t > divs[i]) { t /= divs[i]; i++; } diff --git a/common/lib/buffer.cpp b/common/lib/buffer.cpp index 8fbd39622..318021bf8 100644 --- a/common/lib/buffer.cpp +++ b/common/lib/buffer.cpp @@ -30,45 +30,24 @@ using namespace villas; Buffer::Buffer(size_t sz) : - len(0), - size(sz) -{ - buf = new char[size]; - if (!buf) - throw MemoryAllocationError(); - - memset(buf, 0, size); -} - -Buffer::~Buffer() -{ - delete[] buf; -} + buf(sz, 0) +{ } void Buffer::clear() { - len = 0; + buf.clear(); } int Buffer::append(const char *data, size_t l) { - if (len + l > size) { - size = len + l; - buf = (char *) realloc(buf, size); - if (!buf) - return -1; - } - - memcpy(buf + len, data, l); - - len += l; + buf.insert(buf.end(), data, data+l); return 0; } int Buffer::parseJson(json_t **j) { - *j = json_loadb(buf, len, 0, nullptr); + *j = json_loadb(buf.data(), buf.size(), 0, nullptr); if (!*j) return -1; @@ -79,17 +58,11 @@ int Buffer::appendJson(json_t *j, int flags) { size_t l; -retry: l = json_dumpb(j, buf + len, size - len, flags); - if (size < len + l) { - buf = (char *) realloc(buf, len + l); - if (!buf) - return -1; - - size = len + l; +retry: l = json_dumpb(j, buf.data() + buf.size(), buf.capacity() - buf.size(), flags); + if (buf.capacity() < buf.size() + l) { + buf.reserve(buf.size() + l); goto retry; } - len += l; - return 0; } diff --git a/common/lib/dsp/pid.cpp b/common/lib/dsp/pid.cpp index 40a7f2110..d992829bf 100644 --- a/common/lib/dsp/pid.cpp +++ b/common/lib/dsp/pid.cpp @@ -33,7 +33,9 @@ PID::PID(double _dt, double _max, double _min, double _Kp, double _Kd, double _K min(_min), Kp(_Kp), Kd(_Kd), - Ki(_Ki) + Ki(_Ki), + pre_error(0), + integral(0) { } double PID::calculate(double setpoint, double pv) diff --git a/common/lib/hist.cpp b/common/lib/hist.cpp index 8d7b1be2e..df4f47a0e 100644 --- a/common/lib/hist.cpp +++ b/common/lib/hist.cpp @@ -35,17 +35,20 @@ using namespace villas::utils; namespace villas { Hist::Hist(int buckets, Hist::cnt_t wu) : - warmup(wu) -{ - for ( int i = 0; i::min()), + lowest(std::numeric_limits::max()), + last(), + total(0), + warmup(wu), + higher(0), + lower(0), + data(buckets, 0), + _m{0, 0}, + _s{0, 0} +{ } void Hist::put(double value) { @@ -66,10 +69,10 @@ void Hist::put(double value) high = getMean() + 3 * getStddev(); resolution = (high - low) / data.size(); } - else if (data.size() && (total == warmup) && (warmup == 0)){ - // there is no warmup phase - // TODO resolution = ? - } + else if (data.size() && (total == warmup) && (warmup == 0)) { + // there is no warmup phase + // TODO resolution = ? + } else { idx_t idx = std::round((value - low) / resolution); @@ -99,7 +102,6 @@ void Hist::put(double value) _m[1] = _m[0]; _s[1] = _s[0]; } - } void Hist::reset() diff --git a/common/lib/kernel/kernel.cpp b/common/lib/kernel/kernel.cpp index 26a71aaa5..306acb709 100644 --- a/common/lib/kernel/kernel.cpp +++ b/common/lib/kernel/kernel.cpp @@ -135,7 +135,7 @@ int villas::kernel::module_set_param(const char *module, const char *param, cons snprintf(fn, sizeof(fn), "%s/module/%s/parameters/%s", SYSFS_PATH, module, param); f = fopen(fn, "w"); if (!f) - serror("Failed set parameter %s for kernel module %s to %s", module, param, value); + throw RuntimeError("Failed set parameter {} for kernel module {} to {}", module, param, value); debug(LOG_KERNEL | 5, "Set parameter %s of kernel module %s to %s", module, param, value); fprintf(f, "%s", value); diff --git a/common/lib/kernel/pci.cpp b/common/lib/kernel/pci.cpp index 091b787d6..482d49380 100644 --- a/common/lib/kernel/pci.cpp +++ b/common/lib/kernel/pci.cpp @@ -57,7 +57,7 @@ DeviceList::DeviceList() Id id; Slot slot; - struct { const char *s; int *p; } map[] = { + struct { const char *s; unsigned int *p; } map[] = { { "vendor", &id.vendor }, { "device", &id.device } }; diff --git a/common/lib/kernel/vfio.cpp b/common/lib/kernel/vfio.cpp index c29373c4a..c677f4eb1 100644 --- a/common/lib/kernel/vfio.cpp +++ b/common/lib/kernel/vfio.cpp @@ -718,7 +718,7 @@ Device::pciMsiFind(int nos[]) } while ((col = strtok(nullptr, " "))); - ret = sscanf(last, "vfio-msi[%u](%12[0-9:])", &idx, name); + ret = sscanf(last, "vfio-msi[%d](%12[0-9:])", &idx, name); if (ret == 2) { if (strstr(this->name.c_str(), name) == this->name.c_str()) nos[idx] = irq; diff --git a/common/tests/unit/advio.cpp b/common/tests/unit/advio.cpp index a97e282a4..032a5f7a0 100644 --- a/common/tests/unit/advio.cpp +++ b/common/tests/unit/advio.cpp @@ -227,8 +227,8 @@ Test(advio, append) char c; fseek(af->file, 0, SEEK_SET); if (af->file) { - while ((c = getc(af->file)) != EOF) - putchar(c); + while ((c = getc(af->file)) != EOF) + putchar(c); } len = afwrite(append1, 1, 64, af); diff --git a/common/tests/unit/tsc.cpp b/common/tests/unit/tsc.cpp index 5fa47f7fd..c73e7392d 100644 --- a/common/tests/unit/tsc.cpp +++ b/common/tests/unit/tsc.cpp @@ -28,7 +28,6 @@ #define CNT (1 << 18) -// cppcheck-suppress unknownMacro TestSuite(tsc, .description = "Timestamp counters"); Test(tsc, increasing)