diff --git a/include/villas/api/request.hpp b/include/villas/api/request.hpp index fec01a9e5..00ab58ad7 100644 --- a/include/villas/api/request.hpp +++ b/include/villas/api/request.hpp @@ -54,7 +54,6 @@ protected: public: std::string uri; - int method; std::smatch matches; json_t *body; @@ -68,14 +67,15 @@ public: OPTIONS, PUT, PATCH - }; + } method; Request(Session *s) : session(s), - body(nullptr) - { - logger = logging.get("api:request"); - } + logger(logging.get("api:request")), + body(nullptr), + factory(nullptr), + method(Method::UNKNOWN) + { } virtual ~Request() { @@ -106,7 +106,7 @@ public: make(Session *s) = 0; static Request * - make(Session *s, const std::string &uri, int meth); + make(Session *s, const std::string &uri, Request::Method meth); }; template diff --git a/include/villas/hooks/limit_rate.hpp b/include/villas/hooks/limit_rate.hpp index ba401dba1..db5aa8b0f 100644 --- a/include/villas/hooks/limit_rate.hpp +++ b/include/villas/hooks/limit_rate.hpp @@ -46,10 +46,10 @@ protected: public: LimitRateHook(struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) : LimitHook(p, n, fl, prio, en), - mode(LIMIT_RATE_LOCAL) - { - last = (timespec) { 0, 0 }; - } + mode(LIMIT_RATE_LOCAL), + deadtime(0), + last({0, 0}) + { } virtual void setRate(double rate, double maxRate = -1) { diff --git a/lib/api.cpp b/lib/api.cpp index 0fc8cac9f..e5d1989de 100644 --- a/lib/api.cpp +++ b/lib/api.cpp @@ -42,11 +42,10 @@ InvalidMethod::InvalidMethod(Request *req) : { } Api::Api(SuperNode *sn) : + logger(logging.get("api")), state(State::INITIALIZED), super_node(sn) -{ - logger = logging.get("api"); -} +{ } Api::~Api() { diff --git a/lib/api/request.cpp b/lib/api/request.cpp index f8436c02f..c8f0f53b2 100644 --- a/lib/api/request.cpp +++ b/lib/api/request.cpp @@ -28,7 +28,7 @@ using namespace villas; using namespace villas::node::api; -Request * RequestFactory::make(Session *s, const std::string &uri, int meth) +Request * RequestFactory::make(Session *s, const std::string &uri, Request::Method meth) { for (auto *rf : plugin::Registry::lookup()) { std::smatch mr; diff --git a/lib/api/response.cpp b/lib/api/response.cpp index fc86c7a97..3f3de59e9 100644 --- a/lib/api/response.cpp +++ b/lib/api/response.cpp @@ -28,11 +28,10 @@ using namespace villas::node::api; Response::Response(Session *s, json_t *resp) : session(s), + logger(logging.get("api:response")), response(resp), code(HTTP_STATUS_OK) -{ - logger = logging.get("api:response"); -} +{ } Response::~Response() { diff --git a/lib/api/session.cpp b/lib/api/session.cpp index 0134bfaab..3f02caea6 100644 --- a/lib/api/session.cpp +++ b/lib/api/session.cpp @@ -37,10 +37,9 @@ using namespace villas::node; using namespace villas::node::api; Session::Session(lws *w) : - wsi(w) + wsi(w), + logger(logging.get("api:session")) { - logger = logging.get("api:session"); - lws_context *ctx = lws_get_context(wsi); void *user_ctx = lws_context_user(ctx); @@ -127,11 +126,11 @@ void Session::open(void *in, size_t len) char buf[32]; unsigned long contentLength; - int meth; + Request::Method meth; std::string uri = reinterpret_cast(in); try { - meth = getRequestMethod(wsi); + meth = (Request::Method) getRequestMethod(wsi); if (meth == Request::Method::UNKNOWN) throw RuntimeError("Invalid request method"); diff --git a/lib/config.cpp b/lib/config.cpp index 4fbfacbe4..946d7cd12 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -43,10 +43,9 @@ using namespace villas; using namespace villas::node; Config::Config() : + logger(logging.get("config")), root(nullptr) -{ - logger = logging.get("config"); -} +{ } Config::Config(const std::string &u) : Config() diff --git a/lib/formats/csv.cpp b/lib/formats/csv.cpp index 54fc5593a..cd8d88fbe 100644 --- a/lib/formats/csv.cpp +++ b/lib/formats/csv.cpp @@ -183,7 +183,7 @@ void csv_header(struct io *io, const struct sample *smp) if (sig->name) fprintf(f, "%s", sig->name); else - fprintf(f, "signal%d", i); + fprintf(f, "signal%u", i); if (sig->unit) fprintf(f, "[%s]", sig->unit); diff --git a/lib/formats/iotagent_ul.cpp b/lib/formats/iotagent_ul.cpp index 75eb8e7f7..c65ba16f9 100644 --- a/lib/formats/iotagent_ul.cpp +++ b/lib/formats/iotagent_ul.cpp @@ -46,7 +46,7 @@ int iotagent_ul_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, str printed += snprintf(buf + printed, len - printed, "%s|%f|", sig->name, smp->data[i].f); else { char name[32]; - snprintf(name, 32, "signal_%d", i); + snprintf(name, 32, "signal_%u", i); printed += snprintf(buf + printed, len - printed, "%s|%f|", name, smp->data[i].f); } } diff --git a/lib/formats/json_reserve.cpp b/lib/formats/json_reserve.cpp index 84c8108a6..5a6dd0081 100644 --- a/lib/formats/json_reserve.cpp +++ b/lib/formats/json_reserve.cpp @@ -57,7 +57,7 @@ static int json_reserve_pack_sample(struct io *io, json_t **j, struct sample *sm json_name = json_string(sig->name); else { char name[32]; - snprintf(name, 32, "signal_%d", i); + snprintf(name, 32, "signal%u", i); json_name = json_string(name); } diff --git a/lib/formats/raw.cpp b/lib/formats/raw.cpp index 79898f869..6b1e56d06 100644 --- a/lib/formats/raw.cpp +++ b/lib/formats/raw.cpp @@ -56,15 +56,17 @@ int raw_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct samp int o = 0; size_t nlen; - int8_t *i8 = (int8_t *) buf; - int16_t *i16 = (int16_t *) buf; - int32_t *i32 = (int32_t *) buf; - int64_t *i64 = (int64_t *) buf; - float *f32 = (float *) buf; - double *f64 = (double *) buf; + void *vbuf = (char *) buf; // avoid warning about invalid pointer cast + + int8_t *i8 = (int8_t *) vbuf; + int16_t *i16 = (int16_t *) vbuf; + int32_t *i32 = (int32_t *) vbuf; + int64_t *i64 = (int64_t *) vbuf; + float *f32 = (float *) vbuf; + double *f64 = (double *) vbuf; #ifdef HAS_128BIT - __int128 *i128 = (__int128 *) buf; - __float128 *f128 = (__float128 *) buf; + __int128 *i128 = (__int128 *) vbuf; + __float128 *f128 = (__float128 *) vbuf; #endif int bits = 1 << (io->flags >> 24); @@ -226,8 +228,8 @@ int raw_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct samp break; #ifdef HAS_128BIT case 128: - f128[o++] = SWAP_FLOAT_HTOX(io->flags & RAW_BIG_ENDIAN, 128, std::real(data->z); - f128[o++] = SWAP_FLOAT_HTOX(io->flags & RAW_BIG_ENDIAN, 128, std::imag(data->z); + f128[o++] = SWAP_FLOAT_HTOX(io->flags & RAW_BIG_ENDIAN, 128, std::real(data->z)); + f128[o++] = SWAP_FLOAT_HTOX(io->flags & RAW_BIG_ENDIAN, 128, std::imag(data->z)); break; #endif } @@ -247,15 +249,17 @@ out: if (wbytes) int raw_sscan(struct io *io, const char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt) { - int8_t *i8 = (int8_t *) buf; - int16_t *i16 = (int16_t *) buf; - int32_t *i32 = (int32_t *) buf; - int64_t *i64 = (int64_t *) buf; - float *f32 = (float *) buf; - double *f64 = (double *) buf; + void *vbuf = (void *) buf; // avoid warning about invalid pointer cast + + int8_t *i8 = (int8_t *) vbuf; + int16_t *i16 = (int16_t *) vbuf; + int32_t *i32 = (int32_t *) vbuf; + int64_t *i64 = (int64_t *) vbuf; + float *f32 = (float *) vbuf; + double *f64 = (double *) vbuf; #ifdef HAS_128BIT - __int128 *i128 = (__int128 *) buf; - __float128 *f128 = (__float128 *) buf; + __int128 *i128 = (__int128 *) vbuf; + __float128 *f128 = (__float128 *) vbuf; #endif /* The raw format can not encode multiple samples in one buffer diff --git a/lib/formats/villas_human.cpp b/lib/formats/villas_human.cpp index 10903e19c..af7534522 100644 --- a/lib/formats/villas_human.cpp +++ b/lib/formats/villas_human.cpp @@ -51,7 +51,7 @@ static size_t villas_human_sprint_single(struct io *io, char *buf, size_t len, c } if (io->flags & (int) SampleFlags::HAS_SEQUENCE) { - if (io->flags & (int) SampleFlags::HAS_SEQUENCE) + if (smp->flags & (int) SampleFlags::HAS_SEQUENCE) off += snprintf(buf + off, len - off, "(%" PRIu64 ")", smp->sequence); } @@ -214,7 +214,7 @@ void villas_human_header(struct io *io, const struct sample *smp) if (sig->name) fprintf(f, "%c%s", io->separator, sig->name); else - fprintf(f, "%csignal%d", io->separator, i); + fprintf(f, "%csignal%u", io->separator, i); if (sig->unit) fprintf(f, "[%s]", sig->unit); diff --git a/lib/hook.cpp b/lib/hook.cpp index 8645bbad0..5c8829f14 100644 --- a/lib/hook.cpp +++ b/lib/hook.cpp @@ -39,17 +39,17 @@ using namespace villas; using namespace villas::node; Hook::Hook(struct vpath *p, struct vnode *n, int fl, int prio, bool en) : + logger(logging.get("hook")), state(State::INITIALIZED), flags(fl), priority(prio), enabled(en), path(p), - node(n) + node(n), + cfg(nullptr) { int ret; - logger = logging.get("hook"); - ret = signal_list_init(&signals); if (ret) throw RuntimeError("Failed to initialize signal list"); @@ -61,7 +61,7 @@ Hook::Hook(struct vpath *p, struct vnode *n, int fl, int prio, bool en) : Hook::~Hook() { int ret __attribute__((unused)); - + ret = signal_list_destroy(&signals); } diff --git a/lib/hooks/average.cpp b/lib/hooks/average.cpp index 7bdd9e6a6..b5353d714 100644 --- a/lib/hooks/average.cpp +++ b/lib/hooks/average.cpp @@ -46,7 +46,8 @@ protected: public: AverageHook(struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) : - Hook(p, n, fl, prio, en) + Hook(p, n, fl, prio, en), + offset(0) { int ret; diff --git a/lib/hooks/dp.cpp b/lib/hooks/dp.cpp index 5f9c61375..56d729659 100644 --- a/lib/hooks/dp.cpp +++ b/lib/hooks/dp.cpp @@ -118,7 +118,17 @@ public: DPHook(struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) : Hook(p, n, fl, prio, en), - inverse(0) + signal_name(nullptr), + signal_index(0), + offset(0), + inverse(0), + f0(50.0), + timestep(50e-6), + time(), + steps(0), + coeffs(), + fharmonics(), + fharmonics_len(0) { } virtual ~DPHook() diff --git a/lib/hooks/gate.cpp b/lib/hooks/gate.cpp index 14be2a146..4d66e2ef2 100644 --- a/lib/hooks/gate.cpp +++ b/lib/hooks/gate.cpp @@ -61,11 +61,14 @@ public: GateHook(struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) : Hook(p, n, fl, prio, en), mode(Mode::RISING_EDGE), + signalName(), + signalIndex(0), threshold(0.5), duration(-1), samples(-1), previousValue(std::numeric_limits::quiet_NaN()), - active(false) + active(false), + startSequence(0) { } virtual void parse(json_t *cfg) diff --git a/lib/hooks/jitter_calc.cpp b/lib/hooks/jitter_calc.cpp index 6408e971b..618588ad2 100644 --- a/lib/hooks/jitter_calc.cpp +++ b/lib/hooks/jitter_calc.cpp @@ -24,6 +24,7 @@ * @{ */ +#include #include #include @@ -40,10 +41,11 @@ namespace node { class JitterCalcHook : public Hook { protected: - int64_t *jitter_val; - int64_t *delay_series; - int64_t *moving_avg; - int64_t *moving_var; + std::vector jitter_val; + std::vector delay_series; + std::vector moving_avg; + std::vector moving_var; + int64_t delay_mov_sum; int64_t delay_mov_sum_sqrd; int curr_count; @@ -51,35 +53,15 @@ protected: public: JitterCalcHook(struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) : - Hook(p, n, fl, prio, en) - { - size_t sz = GPS_NTP_DELAY_WIN_SIZE; - - jitter_val = new int64_t[sz]; - delay_series = new int64_t[sz]; - moving_avg = new int64_t[sz]; - moving_var = new int64_t[sz]; - - if (!jitter_val || !delay_series || !moving_avg || !moving_var) - throw MemoryAllocationError(); - - memset(jitter_val, 0, sz); - memset(delay_series, 0, sz); - memset(moving_avg, 0, sz); - memset(moving_var, 0, sz); - - delay_mov_sum = 0; - delay_mov_sum_sqrd = 0; - curr_count = 0; - } - - ~JitterCalcHook() - { - delete[] jitter_val; - delete[] delay_series; - delete[] moving_avg; - delete[] moving_var; - } + Hook(p, n, fl, prio, en), + jitter_val(GPS_NTP_DELAY_WIN_SIZE), + delay_series(GPS_NTP_DELAY_WIN_SIZE), + moving_avg(GPS_NTP_DELAY_WIN_SIZE), + moving_var(GPS_NTP_DELAY_WIN_SIZE), + delay_mov_sum(0), + delay_mov_sum_sqrd(0), + curr_count(0) + { } /** * Hook to calculate jitter between GTNET-SKT GPS timestamp and Villas node NTP timestamp. diff --git a/lib/hooks/limit_value.cpp b/lib/hooks/limit_value.cpp index c2370c3b1..4095dc1dd 100644 --- a/lib/hooks/limit_value.cpp +++ b/lib/hooks/limit_value.cpp @@ -48,7 +48,9 @@ protected: public: LimitValueHook(struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) : - Hook(p, n, fl, prio, en) + Hook(p, n, fl, prio, en), + offset(0), + min(0), max(0) { int ret; diff --git a/lib/hooks/print.cpp b/lib/hooks/print.cpp index 6fb1d52e6..4f66f29cb 100644 --- a/lib/hooks/print.cpp +++ b/lib/hooks/print.cpp @@ -47,6 +47,7 @@ protected: public: PrintHook(struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) : Hook(p, n, fl, prio, en), + io(), prefix(nullptr), uri(nullptr) { diff --git a/lib/hooks/scale.cpp b/lib/hooks/scale.cpp index 803024378..aa8caa36b 100644 --- a/lib/hooks/scale.cpp +++ b/lib/hooks/scale.cpp @@ -44,6 +44,8 @@ protected: public: ScaleHook(struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) : Hook(p, n, fl, prio, en), + signal_name(nullptr), + signal_index(0), scale(1), offset(0) { } diff --git a/lib/hooks/stats.cpp b/lib/hooks/stats.cpp index 0f9e53cf6..a71658842 100644 --- a/lib/hooks/stats.cpp +++ b/lib/hooks/stats.cpp @@ -65,6 +65,7 @@ protected: public: StatsReadHook(StatsHook *pa, struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) : Hook(p, n, fl, prio, en), + last(nullptr), parent(pa) { state = State::CHECKED; @@ -98,8 +99,8 @@ class StatsHook : public Hook { friend StatsWriteHook; protected: - StatsReadHook *readHook; - StatsWriteHook *writeHook; + StatsReadHook readHook; + StatsWriteHook writeHook; enum Stats::Format format; int verbose; @@ -115,6 +116,8 @@ public: StatsHook(struct vpath *p, struct vnode *n, int fl, int prio, bool en = true) : Hook(p, n, fl, prio, en), + readHook(this, p, n, fl, prio, en), + writeHook(this, p, n, fl, prio, en), format(Stats::Format::HUMAN), verbose(0), warmup(500), @@ -123,15 +126,9 @@ public: uri() { /* Add child hooks */ - readHook = new StatsReadHook(this, p, n, fl, prio, en); - writeHook = new StatsWriteHook(this, p, n, fl, prio, en); - - if (!readHook || !writeHook) - throw MemoryAllocationError(); - if (node) { - vlist_push(&node->in.hooks, (void *) readHook); - vlist_push(&node->out.hooks, (void *) writeHook); + vlist_push(&node->in.hooks, (void *) &readHook); + vlist_push(&node->out.hooks, (void *) &writeHook); } } @@ -171,7 +168,7 @@ public: { // Only call readHook if it hasnt been added to the node's hook list if (!node) - return readHook->process(smp); + return readHook.process(smp); return Hook::Reason::OK; } diff --git a/lib/kernel/if.cpp b/lib/kernel/if.cpp index 20b5d0aa8..c024cc1e1 100644 --- a/lib/kernel/if.cpp +++ b/lib/kernel/if.cpp @@ -247,7 +247,7 @@ int if_set_affinity(struct interface *i, int affinity) FILE *file; for (int n = 0; n < IF_IRQ_MAX && i->irqs[n]; n++) { - snprintf(filename, sizeof(filename), "/proc/irq/%u/smp_affinity", i->irqs[n]); + snprintf(filename, sizeof(filename), "/proc/irq/%d/smp_affinity", (int) i->irqs[n]); file = fopen(filename, "w"); if (file) { diff --git a/lib/node.cpp b/lib/node.cpp index 26a980953..13c6dec0b 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -285,7 +285,7 @@ int node_start(struct vnode *n) ret = setsockopt(fd, SOL_SOCKET, SO_MARK, &n->fwmark, sizeof(n->fwmark)); if (ret) - serror("Failed to set FW mark for outgoing packets"); + throw RuntimeError("Failed to set FW mark for outgoing packets"); else debug(LOG_SOCKET | 4, "Set FW mark for socket (sd=%u) to %u", fd, n->fwmark); } @@ -295,7 +295,7 @@ int node_start(struct vnode *n) n->state = State::STARTED; n->sequence = 0; - return ret; + return 0; } int node_stop(struct vnode *n) diff --git a/lib/nodes/comedi.cpp b/lib/nodes/comedi.cpp index 5bf91a596..553492607 100644 --- a/lib/nodes/comedi.cpp +++ b/lib/nodes/comedi.cpp @@ -951,9 +951,6 @@ char* comedi_cmd_trigger_src(unsigned int src, char *buf) if (src & TRIG_COUNT) strcat(buf, "count|"); if (src & TRIG_EXT) strcat(buf, "ext|"); if (src & TRIG_INT) strcat(buf, "int|"); -#ifdef TRIG_OTHER - if (src & TRIG_OTHER) strcat(buf, "other|"); -#endif if (strlen(buf) == 0) sprintf(buf, "unknown(0x%08x)", src); diff --git a/lib/nodes/influxdb.cpp b/lib/nodes/influxdb.cpp index 09a76c627..af810d074 100644 --- a/lib/nodes/influxdb.cpp +++ b/lib/nodes/influxdb.cpp @@ -157,7 +157,7 @@ int influxdb_write(struct vnode *n, struct sample *smps[], unsigned cnt, unsigne if (sig->name) strncpy(name, sig->name, sizeof(name)); else - snprintf(name, sizeof(name), "value%d", j); + snprintf(name, sizeof(name), "value%u", j); if (sig->type == SignalType::COMPLEX) { strcatf(&buf, "%s_re=%f, %s_im=%f", diff --git a/lib/nodes/rtp.cpp b/lib/nodes/rtp.cpp index 6c2c5d177..dec6d596e 100644 --- a/lib/nodes/rtp.cpp +++ b/lib/nodes/rtp.cpp @@ -439,7 +439,7 @@ int rtp_stop(struct vnode *n) if (ret) return ret; - return ret; + return 0; } int rtp_destroy(struct vnode *n) @@ -508,7 +508,7 @@ int rtp_type_start(villas::node::SuperNode *sn) } #endif /* WITH_NETEM */ - return ret; + return 0; } int rtp_type_stop() diff --git a/lib/nodes/websocket.cpp b/lib/nodes/websocket.cpp index a4733178c..31efce258 100644 --- a/lib/nodes/websocket.cpp +++ b/lib/nodes/websocket.cpp @@ -273,7 +273,7 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi case LWS_CALLBACK_CLIENT_WRITEABLE: case LWS_CALLBACK_SERVER_WRITEABLE: { - struct sample **smps = (struct sample **) alloca(cnt * sizeof(struct sample *)); + struct sample *smps[cnt]; pulled = queue_pull_many(&c->queue, (void **) smps, cnt); if (pulled > 0) { @@ -318,7 +318,7 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi int avail, enqueued; struct websocket *w = (struct websocket *) n->_vd; - struct sample **smps = (struct sample **) alloca(cnt * sizeof(struct sample *)); + struct sample *smps[cnt]; if (!smps) { warning("Failed to allocate memory for connection: %s", websocket_connection_name(c)); break; diff --git a/lib/sample.cpp b/lib/sample.cpp index 4f360cff6..5cde5337f 100644 --- a/lib/sample.cpp +++ b/lib/sample.cpp @@ -235,7 +235,7 @@ int sample_cmp(struct sample *a, struct sample *b, double epsilon, int flags) /* Compare data */ if (flags & (int) SampleFlags::HAS_DATA) { if (a->length != b->length) { - printf("length: %d != %d\n", a->length, b->length); + printf("length: %u != %u\n", a->length, b->length); return 4; } @@ -247,28 +247,28 @@ int sample_cmp(struct sample *a, struct sample *b, double epsilon, int flags) switch (sample_format(a, i)) { case SignalType::FLOAT: if (fabs(a->data[i].f - b->data[i].f) > epsilon) { - printf("data[%d].f: %f != %f\n", i, a->data[i].f, b->data[i].f); + printf("data[%u].f: %f != %f\n", i, a->data[i].f, b->data[i].f); return 5; } break; case SignalType::INTEGER: if (a->data[i].i != b->data[i].i) { - printf("data[%d].i: %" PRId64 " != %" PRId64 "\n", i, a->data[i].i, b->data[i].i); + printf("data[%u].i: %" PRId64 " != %" PRId64 "\n", i, a->data[i].i, b->data[i].i); return 5; } break; case SignalType::BOOLEAN: if (a->data[i].b != b->data[i].b) { - printf("data[%d].b: %s != %s\n", i, a->data[i].b ? "true" : "false", b->data[i].b ? "true" : "false"); + printf("data[%u].b: %s != %s\n", i, a->data[i].b ? "true" : "false", b->data[i].b ? "true" : "false"); return 5; } break; case SignalType::COMPLEX: if (std::abs(a->data[i].z - b->data[i].z) > epsilon) { - printf("data[%d].z: %f+%fi != %f+%fi\n", i, std::real(a->data[i].z), std::imag(a->data[i].z), std::real(b->data[i].z), std::imag(b->data[i].z)); + printf("data[%u].z: %f+%fi != %f+%fi\n", i, std::real(a->data[i].z), std::imag(a->data[i].z), std::real(b->data[i].z), std::imag(b->data[i].z)); return 5; } break; diff --git a/lib/signal_data.cpp b/lib/signal_data.cpp index 0e76c451f..78cae14de 100644 --- a/lib/signal_data.cpp +++ b/lib/signal_data.cpp @@ -61,7 +61,6 @@ void signal_data_cast(union signal_data *data, const struct signal *from, const case SignalType::BOOLEAN: switch(from->type) { case SignalType::BOOLEAN: - data->b = data->b; break; case SignalType::INTEGER: @@ -87,7 +86,6 @@ void signal_data_cast(union signal_data *data, const struct signal *from, const break; case SignalType::INTEGER: - data->i = data->i; break; case SignalType::FLOAT: @@ -113,7 +111,6 @@ void signal_data_cast(union signal_data *data, const struct signal *from, const break; case SignalType::FLOAT: - data->f = data->f; break; case SignalType::COMPLEX: @@ -139,7 +136,6 @@ void signal_data_cast(union signal_data *data, const struct signal *from, const break; case SignalType::COMPLEX: - data->z = data->z; break; default: { } diff --git a/lib/signal_list.cpp b/lib/signal_list.cpp index 5b77accb0..13577cf41 100644 --- a/lib/signal_list.cpp +++ b/lib/signal_list.cpp @@ -87,7 +87,7 @@ int signal_list_generate(struct vlist *list, unsigned len, enum SignalType typ) char name[32]; for (unsigned i = 0; i < len; i++) { - snprintf(name, sizeof(name), "signal%d", i); + snprintf(name, sizeof(name), "signal%u", i); struct signal *sig = signal_create(name, nullptr, typ); if (!sig) diff --git a/lib/web.cpp b/lib/web.cpp index 5fcc33804..96397611b 100644 --- a/lib/web.cpp +++ b/lib/web.cpp @@ -176,19 +176,15 @@ void Web::worker() Web::Web(Api *a) : state(State::INITIALIZED), + logger(logging.get("web")), + context(nullptr), + vhost(nullptr), + port(getuid() > 0 ? 8080 : 80), htdocs(WEB_PATH), api(a) { - int lvl = LLL_ERR | LLL_WARN | LLL_NOTICE; - /** @todo: Port to C++: add LLL_DEBUG and others if trace log level is activated */ - - lws_set_log_level(lvl, lwsLogger); - - /* Default values */ - port = getuid() > 0 ? 8080 : 80; - - logger = logging.get("web"); + lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE, lwsLogger); } int Web::parse(json_t *cfg) diff --git a/src/villas-hook.cpp b/src/villas-hook.cpp index 19ed71d51..eab43d953 100644 --- a/src/villas-hook.cpp +++ b/src/villas-hook.cpp @@ -62,6 +62,8 @@ public: stop(false), format("villas.human"), dtypes("64f"), + p(), + io(), cnt(1) { int ret; diff --git a/src/villas-pipe.cpp b/src/villas-pipe.cpp index b78ce8365..86e63de7b 100644 --- a/src/villas-pipe.cpp +++ b/src/villas-pipe.cpp @@ -86,7 +86,7 @@ public: ~PipeDirection() { int ret __attribute__((unused)); - + ret = pool_destroy(&pool); } @@ -166,7 +166,7 @@ public: goto leave; } -leave2: +leave2: logger->info("Send thread stopped"); return; @@ -243,10 +243,12 @@ public: Pipe(int argc, char *argv[]) : Tool(argc, argv, "pipe"), stop(false), + io(), timeout(0), reverse(false), format("villas.human"), dtypes("64f"), + cfg_cli(json_object()), enable_send(true), enable_recv(true), limit_send(-1), @@ -257,8 +259,6 @@ public: ret = memory_init(DEFAULT_NR_HUGEPAGES); if (ret) throw RuntimeError("Failed to initialize memory"); - - cfg_cli = json_object(); } ~Pipe() diff --git a/src/villas-relay.cpp b/src/villas-relay.cpp index b7e3fc243..921d6885d 100644 --- a/src/villas-relay.cpp +++ b/src/villas-relay.cpp @@ -224,6 +224,8 @@ void RelayConnection::read(void *in, size_t len) Relay::Relay(int argc, char *argv[]) : Tool(argc, argv, "relay"), stop(false), + context(nullptr), + vhost(nullptr), loopback(false), port(8088), protocol("live") diff --git a/src/villas-signal.cpp b/src/villas-signal.cpp index d336b5f3b..1499403b1 100644 --- a/src/villas-signal.cpp +++ b/src/villas-signal.cpp @@ -55,6 +55,9 @@ public: Signal(int argc, char *argv[]) : Tool(argc, argv, "signal"), stop(false), + n(), + io(), + q(), format("villas.human") { int ret; diff --git a/src/villas-test-cmp.cpp b/src/villas-test-cmp.cpp index 2da183486..0602c6f57 100644 --- a/src/villas-test-cmp.cpp +++ b/src/villas-test-cmp.cpp @@ -78,15 +78,10 @@ public: ~TestCmpSide() noexcept(false) { - int ret; + int ret __attribute((unused)); ret = io_close(&io); - if (ret) - throw RuntimeError("Failed to close IO"); - ret = io_destroy(&io); - if (ret) - throw RuntimeError("Failed to destroy IO"); sample_decref(sample); } @@ -97,6 +92,7 @@ class TestCmp : public Tool { public: TestCmp(int argc, char *argv[]) : Tool(argc, argv, "test-cmp"), + pool(), epsilon(1e-9), format("villas.human"), dtypes("64f"), diff --git a/tests/unit/config.cpp b/tests/unit/config.cpp index ad0b308ce..0c99e7c23 100644 --- a/tests/unit/config.cpp +++ b/tests/unit/config.cpp @@ -31,6 +31,7 @@ namespace fs = std::filesystem; using namespace villas::node; +// cppcheck-suppress syntaxError Test(config, env) { const char *cfg_f = "test = \"${MY_ENV_VAR}\"\n"; @@ -54,7 +55,6 @@ Test(config, env) cr_assert_str_eq("mobydick", json_string_value(j)); } - Test(config, include) { const char *cfg_f2 = "magic = 1234\n"; diff --git a/tests/unit/config_json.cpp b/tests/unit/config_json.cpp index 4d77cff5a..2005beb73 100644 --- a/tests/unit/config_json.cpp +++ b/tests/unit/config_json.cpp @@ -59,6 +59,7 @@ const char *json_example = "{\n" " ]\n" "}"; +// cppcheck-suppress syntaxError Test(config, config_to_json) { int ret; diff --git a/tests/unit/io.cpp b/tests/unit/io.cpp index 0949584e2..d986d3ea4 100644 --- a/tests/unit/io.cpp +++ b/tests/unit/io.cpp @@ -217,6 +217,7 @@ ParameterizedTestParameters(io, lowlevel) return params; } +// cppcheck-suppress unknownMacro ParameterizedTest(Param *p, io, lowlevel, .init = init_memory) { int ret; diff --git a/tests/unit/json.cpp b/tests/unit/json.cpp index a47393cb1..8ac6a996d 100644 --- a/tests/unit/json.cpp +++ b/tests/unit/json.cpp @@ -34,6 +34,7 @@ struct param { char *json; }; +// cppcheck-suppress syntaxError ParameterizedTestParameters(json, json_load_cli) { const auto d = cr_strdup; diff --git a/tests/unit/mapping.cpp b/tests/unit/mapping.cpp index 34c3c8b7d..7e5ed3b5d 100644 --- a/tests/unit/mapping.cpp +++ b/tests/unit/mapping.cpp @@ -30,6 +30,7 @@ using namespace villas; +// cppcheck-suppress syntaxError Test(mapping, parse_nodes) { int ret; diff --git a/tests/unit/memory.cpp b/tests/unit/memory.cpp index 0fffc114d..038f3d597 100644 --- a/tests/unit/memory.cpp +++ b/tests/unit/memory.cpp @@ -40,6 +40,7 @@ TheoryDataPoints(memory, aligned) = { DataPoints(struct memory_type *, &memory_heap, &memory_mmap_hugetlb, &memory_mmap_hugetlb) }; +// cppcheck-suppress unknownMacro Theory((size_t len, size_t align, struct memory_type *mt), memory, aligned, .init = init_memory) { int ret; void *ptr; diff --git a/tests/unit/pool.cpp b/tests/unit/pool.cpp index 4eb22279c..c2633c0ae 100644 --- a/tests/unit/pool.cpp +++ b/tests/unit/pool.cpp @@ -49,6 +49,7 @@ ParameterizedTestParameters(pool, basic) return cr_make_param_array(struct param, params, ARRAY_LEN(params)); } +// cppcheck-suppress unknownMacro ParameterizedTest(struct param *p, pool, basic, .init = init_memory) { int ret; diff --git a/tests/unit/queue_signalled.cpp b/tests/unit/queue_signalled.cpp index 25a310cd9..80acbd108 100644 --- a/tests/unit/queue_signalled.cpp +++ b/tests/unit/queue_signalled.cpp @@ -127,6 +127,7 @@ ParameterizedTestParameters(queue_signalled, simple) return cr_make_param_array(struct param, params, ARRAY_LEN(params)); } +// cppcheck-suppress unknownMacro ParameterizedTest(struct param *param, queue_signalled, simple, .timeout = 5, .init = init_memory) { int ret; diff --git a/tests/unit/signal.cpp b/tests/unit/signal.cpp index 9e894b086..4fc5032f2 100644 --- a/tests/unit/signal.cpp +++ b/tests/unit/signal.cpp @@ -26,6 +26,7 @@ extern void init_memory(); +// cppcheck-suppress unknownMacro Test(signal, parse, .init = init_memory) { int ret; struct signal sig; @@ -36,7 +37,7 @@ Test(signal, parse, .init = init_memory) { str = "1"; sig.type = SignalType::INTEGER; - + ret = signal_data_parse_str(&sd, &sig, str, &end); cr_assert_eq(ret, 0); cr_assert_eq(end, str + strlen(str)); @@ -44,7 +45,7 @@ Test(signal, parse, .init = init_memory) { str = "1.2"; sig.type = SignalType::FLOAT; - + ret = signal_data_parse_str(&sd, &sig, str, &end); cr_assert_eq(ret, 0); cr_assert_eq(end, str + strlen(str)); @@ -52,7 +53,7 @@ Test(signal, parse, .init = init_memory) { str = "1"; sig.type = SignalType::BOOLEAN; - + ret = signal_data_parse_str(&sd, &sig, str, &end); cr_assert_eq(ret, 0); cr_assert_eq(end, str + strlen(str)); @@ -60,7 +61,7 @@ Test(signal, parse, .init = init_memory) { str = "1"; sig.type = SignalType::COMPLEX; - + ret = signal_data_parse_str(&sd, &sig, str, &end); cr_assert_eq(ret, 0); cr_assert_eq(end, str + strlen(str)); @@ -69,7 +70,7 @@ Test(signal, parse, .init = init_memory) { str = "-1-3i"; sig.type = SignalType::COMPLEX; - + ret = signal_data_parse_str(&sd, &sig, str, &end); cr_assert_eq(ret, 0); cr_assert_eq(end, str + strlen(str)); @@ -78,7 +79,7 @@ Test(signal, parse, .init = init_memory) { str = "-3i"; sig.type = SignalType::COMPLEX; - + ret = signal_data_parse_str(&sd, &sig, str, &end); cr_assert_eq(ret, 0); cr_assert_eq(end, str + strlen(str));