From f73c85248a2d5ea13ae94a4254b101c5bd5d8c21 Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Wed, 17 May 2023 04:01:56 +0000 Subject: [PATCH] Add basic cppcheck checks, fix possible uninitialized pointer reuse in API, ignore sqrt() NaN definition warning. --- .github/workflows/test.yml | 8 ++++++++ src/cjson.c | 2 +- src/iperf_api.c | 7 +++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3b3081531..afc960d96 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,14 @@ name: test on: [push, pull_request] jobs: + cppcheck-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: install dependencies + run: | + sudo apt-get -y update && sudo apt-get install -y cppcheck && \ + cppcheck . --force --inline-suppr build-test-latest: runs-on: ubuntu-latest steps: diff --git a/src/cjson.c b/src/cjson.c index ed8c3fda6..70a88a03b 100644 --- a/src/cjson.c +++ b/src/cjson.c @@ -134,7 +134,7 @@ CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item) { if (!cJSON_IsNumber(item)) { - return (double) NAN; + return (double) NAN; // cppcheck-suppress invalidFunctionArg } return item->valuedouble; diff --git a/src/iperf_api.c b/src/iperf_api.c index a2cd53a2c..0759b2076 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -4487,12 +4487,15 @@ iperf_add_stream(struct iperf_test *test, struct iperf_stream *sp) // and changing it would break multi-stream tests between old // and new iperf3 versions. i = 2; + prev = NULL; SLIST_FOREACH(n, &test->streams, streams) { prev = n; ++i; } - SLIST_INSERT_AFTER(prev, sp, streams); - sp->id = i; + if (prev) { + SLIST_INSERT_AFTER(prev, sp, streams); + sp->id = i; + } } }