Skip to content

Conversation

@Danielius1922
Copy link
Member

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented May 4, 2025

Walkthrough

The changes primarily refactor string handling in test and implementation code, replacing std::string_view with std::string for URI and resource type constants, and updating function signatures and usages accordingly. Several C source files are refactored for clarity and safety in URI and path handling, including improved assertions, error checks, and centralized helper functions. Minor bug fixes and type consistency improvements are also made.

Changes

File(s) Change Summary
api/oc_endpoint.c Adds conditional deallocation of ipaddress on IPv6 parsing failure to prevent memory leaks.
api/plgd/device-provisioning-client/plgd_dps_dhcp.c Changes function signatures and local variable types from ssize_t to int, simplifies control flow, and refactors iteration logic for consistency.
api/plgd/device-provisioning-client/plgd_dps_security.c Replaces an assertion with explicit error handling when converting owner UUID to string fails.
api/oc_client_api.c, messaging/coap/engine.c, messaging/coap/observe.c, api/oc_server_api.c Refactors URI handling: introduces local variables for URIs, adds assertions, and clarifies pointer arithmetic for blockwise operations. Removes some assertions in oc_do_request.
api/oc_client_api_internal.h Updates oc_do_request declaration to add OC_NONNULL(6) attribute.
apps/cloud_server.c Adds buffer overflow check before copying manufacturer key to prevent invalid memory access.
port/linux/storage.c Introduces static helper storage_write_path to centralize and validate path concatenation logic, reducing code duplication.
port/linux/ipadapter.c Refactors network interface address event handling by extracting logic into helper functions for adding/removing interfaces and setting refresh flags; adds small wrapper functions for macros; centralizes socket selection; fixes IPv6 discovery request logging and type correctness.
api/unittest/collectiontest.cpp, api/unittest/discovery/discovery.cpp, api/unittest/discovery/discovery.h, api/unittest/etagtest.cpp, messaging/coap/unittest/observenotificationstest.cpp, messaging/coap/unittest/blockwisetest.cpp Replaces std::string_view with std::string for URI/resource constants; updates function signatures and usages to match. Adjusts calls to use .c_str() where needed for C APIs.
tests/gtest/Collection.h Updates template function NewCollection to use const std::string & instead of std::string_view for parameters; updates API calls to use .c_str().
api/unittest/resourcetest.cpp Unifies string constant types to const std::string, simplifying usage and removing unnecessary conversions.
api/unittest/discovery/discoveryobservetest.cpp Updates URI argument passing from .data() to .c_str() for C API calls.
security/unittest/doxmtest.cpp Replaces macro OC_ARRAY_SIZE with std::size for array size calculation in test code.
util/oc_compiler.h Adds support for __has_builtin macro and defines OC_SPECULATION_SAFE(x) macro for speculative execution safety.

Sequence Diagram(s)

sequenceDiagram
    participant TestCase
    participant Resource/Collection API
    participant C API

    TestCase->>Resource/Collection API: Create resource/collection (pass std::string)
    Resource/Collection API->>C API: Call with .c_str() for URI/RT
    C API-->>Resource/Collection API: Resource/collection created
    Resource/Collection API-->>TestCase: Resource/collection object returned
Loading
sequenceDiagram
    participant StorageAPI
    participant storage_write_path (helper)
    participant OS/FileSystem

    StorageAPI->>storage_write_path: Validate and concatenate store path
    storage_write_path-->>StorageAPI: Success/Error
    StorageAPI->>OS/FileSystem: Open/write file with full path
Loading

Suggested reviewers

  • jkralik

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52759ba and 5c1421c.

⛔ Files ignored due to path filters (1)
  • .github/workflows/cmake-windows.yml is excluded by !**/*.yml
📒 Files selected for processing (13)
  • api/oc_client_api.c (1 hunks)
  • api/oc_client_api_internal.h (1 hunks)
  • api/oc_endpoint.c (1 hunks)
  • api/oc_server_api.c (1 hunks)
  • api/plgd/device-provisioning-client/plgd_dps_dhcp.c (2 hunks)
  • api/plgd/device-provisioning-client/plgd_dps_security.c (1 hunks)
  • api/unittest/resourcetest.cpp (6 hunks)
  • apps/cloud_server.c (1 hunks)
  • messaging/coap/engine.c (1 hunks)
  • messaging/coap/observe.c (2 hunks)
  • port/linux/ipadapter.c (7 hunks)
  • port/linux/storage.c (3 hunks)
  • util/oc_compiler.h (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (13)
  • api/oc_endpoint.c
  • api/plgd/device-provisioning-client/plgd_dps_security.c
  • api/oc_client_api.c
  • messaging/coap/engine.c
  • util/oc_compiler.h
  • apps/cloud_server.c
  • api/unittest/resourcetest.cpp
  • port/linux/storage.c
  • messaging/coap/observe.c
  • api/oc_client_api_internal.h
  • api/oc_server_api.c
  • api/plgd/device-provisioning-client/plgd_dps_dhcp.c
  • port/linux/ipadapter.c
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ocf-conformance-test-tool
Copy link

🎉 Thank you for your code contribution! To guarantee the change/addition is conformant to the OCF Specification, we would like to ask you to execute OCF Conformance Testing of your change ☝️ when your work is ready to be reviewed.


ℹ️ To verify your latest change (f377812), label this PR with OCF Conformance Testing.

⚠️ Label is removed with every code change.

@Danielius1922 Danielius1922 force-pushed the adam/feature/654-coverity-fixes-1 branch 2 times, most recently from fffd614 to 392ecc9 Compare May 4, 2025 13:21
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fffd614 and 392ecc9.

📒 Files selected for processing (3)
  • docker/apps/Dockerfile.cloud-server-debug-clang (1 hunks)
  • docker/apps/Dockerfile.dps-cloud-server (2 hunks)
  • tools/collect-coverage.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • docker/apps/Dockerfile.dps-cloud-server
  • docker/apps/Dockerfile.cloud-server-debug-clang
⏰ Context from checks skipped due to timeout of 90000ms (40)
  • GitHub Check: build-and-push-images (cloud-server, Release, docker/apps/Dockerfile.cloud-server) / build-and-push-image
  • GitHub Check: build-and-push-dps-images (dps-cloud-server-debug, Debug, -DOC_DEBUG_ENABLED=ON -DOC_LOG_MAXIMUM_... / build-and-push-image
  • GitHub Check: plgd-device-test (cloud-server-release-discovery-resource-observable-access-in-RFOTM-rep-realloc,... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-images (cloud-server, Release, docker/apps/Dockerfile.cloud-server) / build-and-push-image
  • GitHub Check: build-and-push-dps-images (dps-cloud-server-debug, Debug, -DOC_DEBUG_ENABLED=ON -DOC_LOG_MAXIMUM_... / build-and-push-image
  • GitHub Check: plgd-device-test (cloud-server-release-discovery-resource-observable-access-in-RFOTM-rep-realloc,... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-images (cloud-server, Release, docker/apps/Dockerfile.cloud-server) / build-and-push-image
  • GitHub Check: build-and-push-dps-images (dps-cloud-server-debug, Debug, -DOC_DEBUG_ENABLED=ON -DOC_LOG_MAXIMUM_... / build-and-push-image
  • GitHub Check: plgd-device-test (cloud-server-release-discovery-resource-observable-access-in-RFOTM-rep-realloc,... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-images (cloud-server, Release, docker/apps/Dockerfile.cloud-server) / build-and-push-image
  • GitHub Check: build-and-push-dps-images (dps-cloud-server-debug, Debug, -DOC_DEBUG_ENABLED=ON -DOC_LOG_MAXIMUM_... / build-and-push-image
  • GitHub Check: plgd-device-test (cloud-server-release-discovery-resource-observable-access-in-RFOTM-rep-realloc,... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-images (cloud-server, Release, docker/apps/Dockerfile.cloud-server) / build-and-push-image
  • GitHub Check: build-and-push-dps-images (dps-cloud-server-debug, Debug, -DOC_DEBUG_ENABLED=ON -DOC_LOG_MAXIMUM_... / build-and-push-image
  • GitHub Check: plgd-device-test (cloud-server-release-discovery-resource-observable-access-in-RFOTM-rep-realloc,... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-images (cloud-server, Release, docker/apps/Dockerfile.cloud-server) / build-and-push-image
  • GitHub Check: build-and-push-dps-images (dps-cloud-server-debug, Debug, -DOC_DEBUG_ENABLED=ON -DOC_LOG_MAXIMUM_... / build-and-push-image
  • GitHub Check: plgd-device-test (cloud-server-release-discovery-resource-observable-access-in-RFOTM-rep-realloc,... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-images (cloud-server, Release, docker/apps/Dockerfile.cloud-server) / build-and-push-image
  • GitHub Check: build-and-push-dps-images (dps-cloud-server-debug, Debug, -DOC_DEBUG_ENABLED=ON -DOC_LOG_MAXIMUM_... / build-and-push-image
  • GitHub Check: plgd-device-test (cloud-server-release-discovery-resource-observable-access-in-RFOTM-rep-realloc,... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-images (cloud-server, Release, docker/apps/Dockerfile.cloud-server) / build-and-push-image
  • GitHub Check: build-and-push-dps-images (dps-cloud-server-debug, Debug, -DOC_DEBUG_ENABLED=ON -DOC_LOG_MAXIMUM_... / build-and-push-image
  • GitHub Check: plgd-device-test (cloud-server-release-discovery-resource-observable-access-in-RFOTM-rep-realloc,... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-images (cloud-server, Release, docker/apps/Dockerfile.cloud-server) / build-and-push-image
  • GitHub Check: build-and-push-dps-images (dps-cloud-server-debug, Debug, -DOC_DEBUG_ENABLED=ON -DOC_LOG_MAXIMUM_... / build-and-push-image
  • GitHub Check: plgd-device-test (cloud-server-release-discovery-resource-observable-access-in-RFOTM-rep-realloc,... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg
  • GitHub Check: build-and-push-images (cloud-server, Release, docker/apps/Dockerfile.cloud-server) / build-and-push-image
  • GitHub Check: build-and-push-dps-images (dps-cloud-server-debug, Debug, -DOC_DEBUG_ENABLED=ON -DOC_LOG_MAXIMUM_... / build-and-push-image
  • GitHub Check: plgd-device-test (cloud-server-release-discovery-resource-observable-access-in-RFOTM-rep-realloc,... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-test (dps-cloud-server-tsan, -DOC_TSAN_ENABLED=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C... / plgd-hub-test-with-cfg

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
CMakeLists.txt (2)

640-642: Prefer target_link_options for linker flags instead of mixing them into libraries
Linker flags like -lgcov or --coverage are currently appended via PRIVATE_LINK_LIBS. Since CMake 3.13+, it’s clearer to use target_link_options(<target> PRIVATE ${COVERAGE_LINK_OPTIONS}) (or a global add_link_options) to distinguish flags from actual libraries.


893-896: Redundant compile/link options on a static library target
target_compile_options(client-server-static PRIVATE ...) and target_link_libraries(client-server-static PRIVATE ...) have no effect for a static library (it doesn’t compile or link sources itself). You can remove these lines or switch them to INTERFACE if the intention is to propagate coverage flags to consumers.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d05767c and 41915e9.

📒 Files selected for processing (1)
  • CMakeLists.txt (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (30)
  • GitHub Check: plgd-device-tests (cloud-server-access-in-RFOTM-concurrent-requests-1, -DOC_RESOURCE_ACCESS_IN_RF... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-tests (cloud-server-discovery-resource-observable-access-in-RFOTM-rep-realloc-concurrent... / plgd-hub-test-with-cfg
  • GitHub Check: cmake_linux (-DOC_IPV4_ENABLED=ON) / unit-test-with-cfg
  • GitHub Check: plgd-device-tests (cloud-server-access-in-RFOTM-concurrent-requests-1, -DOC_RESOURCE_ACCESS_IN_RF... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-tests (cloud-server-discovery-resource-observable-access-in-RFOTM-rep-realloc-concurrent... / plgd-hub-test-with-cfg
  • GitHub Check: cmake_linux (-DOC_IPV4_ENABLED=ON) / unit-test-with-cfg
  • GitHub Check: plgd-device-tests (cloud-server-access-in-RFOTM-concurrent-requests-1, -DOC_RESOURCE_ACCESS_IN_RF... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-tests (cloud-server-discovery-resource-observable-access-in-RFOTM-rep-realloc-concurrent... / plgd-hub-test-with-cfg
  • GitHub Check: cmake_linux (-DOC_IPV4_ENABLED=ON) / unit-test-with-cfg
  • GitHub Check: plgd-device-tests (cloud-server-access-in-RFOTM-concurrent-requests-1, -DOC_RESOURCE_ACCESS_IN_RF... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-tests (cloud-server-discovery-resource-observable-access-in-RFOTM-rep-realloc-concurrent... / plgd-hub-test-with-cfg
  • GitHub Check: cmake_linux (-DOC_IPV4_ENABLED=ON) / unit-test-with-cfg
  • GitHub Check: plgd-device-tests (cloud-server-access-in-RFOTM-concurrent-requests-1, -DOC_RESOURCE_ACCESS_IN_RF... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-tests (cloud-server-discovery-resource-observable-access-in-RFOTM-rep-realloc-concurrent... / plgd-hub-test-with-cfg
  • GitHub Check: cmake_linux (-DOC_IPV4_ENABLED=ON) / unit-test-with-cfg
  • GitHub Check: plgd-device-tests (cloud-server-access-in-RFOTM-concurrent-requests-1, -DOC_RESOURCE_ACCESS_IN_RF... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-tests (cloud-server-discovery-resource-observable-access-in-RFOTM-rep-realloc-concurrent... / plgd-hub-test-with-cfg
  • GitHub Check: cmake_linux (-DOC_IPV4_ENABLED=ON) / unit-test-with-cfg
  • GitHub Check: plgd-device-tests (cloud-server-access-in-RFOTM-concurrent-requests-1, -DOC_RESOURCE_ACCESS_IN_RF... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-tests (cloud-server-discovery-resource-observable-access-in-RFOTM-rep-realloc-concurrent... / plgd-hub-test-with-cfg
  • GitHub Check: cmake_linux (-DOC_IPV4_ENABLED=ON) / unit-test-with-cfg
  • GitHub Check: plgd-device-tests (cloud-server-access-in-RFOTM-concurrent-requests-1, -DOC_RESOURCE_ACCESS_IN_RF... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-tests (cloud-server-discovery-resource-observable-access-in-RFOTM-rep-realloc-concurrent... / plgd-hub-test-with-cfg
  • GitHub Check: cmake_linux (-DOC_IPV4_ENABLED=ON) / unit-test-with-cfg
  • GitHub Check: plgd-device-tests (cloud-server-access-in-RFOTM-concurrent-requests-1, -DOC_RESOURCE_ACCESS_IN_RF... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-tests (cloud-server-discovery-resource-observable-access-in-RFOTM-rep-realloc-concurrent... / plgd-hub-test-with-cfg
  • GitHub Check: cmake_linux (-DOC_IPV4_ENABLED=ON) / unit-test-with-cfg
  • GitHub Check: plgd-device-tests (cloud-server-access-in-RFOTM-concurrent-requests-1, -DOC_RESOURCE_ACCESS_IN_RF... / plgd-device-test-with-cfg
  • GitHub Check: plgd-hub-tests (cloud-server-discovery-resource-observable-access-in-RFOTM-rep-realloc-concurrent... / plgd-hub-test-with-cfg
  • GitHub Check: cmake_linux (-DOC_IPV4_ENABLED=ON) / unit-test-with-cfg

@Danielius1922 Danielius1922 force-pushed the adam/feature/654-coverity-fixes-1 branch from 41915e9 to 1941bee Compare May 5, 2025 08:41
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
tools/collect-coverage.sh (2)

102-109: 🛠️ Refactor suggestion

Improve Clang coverage tool detection and version parsing

The current logic:

  • Uses which llvm-cov-${CLANG_VERSION} 2>/dev/null 1>&2 (confusing redirection ordering; prefer standard command -v ... >/dev/null 2>&1).
  • Extracts the major version via $4 (brittle across different clang --version formats).
  • Assigns GCOV as a single string "llvm-cov-${CLANG_VERSION} gcov", which won’t split into two tokens when invoked.

Apply these diffs to make detection robust and POSIX-compliant:

-	clang --version
-	CLANG_VERSION=$(clang --version | awk 'NR==1 { split($4, v, "."); print v[1] }')
-	if ! which llvm-cov-${CLANG_VERSION} 2>/dev/null 1>&2; then
+	clang --version
+	# Extract first numeric token for robust version parsing
+	CLANG_VERSION=$(clang --version | awk 'NR==1 {
+	  for (i=1; i<=NF; i++) if ($i ~ /^[0-9]+(\.[0-9]+)*/) {
+	    split($i, v, "."); print v[1]; exit
+	  }
+	}')
+	if ! command -v "llvm-cov-${CLANG_VERSION}" >/dev/null 2>&1; then
 		echo "llvm-cov-${CLANG_VERSION} not installed" >&2
 		exit 1
 	fi
-	GCOV="llvm-cov-${CLANG_VERSION} gcov"
+	# Use array to preserve command + subcommand
+	GCOV=( "llvm-cov-${CLANG_VERSION}" "gcov" )

Note: Update the later invocation to expand the array, e.g. --gcov-executable "${GCOV[0]}" and incorporate "${GCOV[@]:1}" if needed.


111-119: 🛠️ Refactor suggestion

Improve GCC coverage tool detection and version parsing

The GCC branch mirrors the Clang logic and has the same issues:

  • Relies on field $4 for version extraction.
  • Uses which … 2>/dev/null 1>&2 instead of command -v.

Proposed diff:

-	gcc --version
-	GCC_VERSION=$(gcc --version | awk 'NR==1 { split($4, v, "."); print v[1] }')
-	if ! which gcov-${GCC_VERSION} 2>/dev/null 1>&2; then
+	gcc --version
+	# Extract first numeric token for robust version parsing
+	GCC_VERSION=$(gcc --version | awk 'NR==1 {
+	  for (i=1; i<=NF; i++) if ($i ~ /^[0-9]+(\.[0-9]+)*/) {
+	    split($i, v, "."); print v[1]; exit
+	  }
+	}')
+	if ! command -v "gcov-${GCC_VERSION}" >/dev/null 2>&1; then
 		echo "gcov-${GCC_VERSION} not installed" >&2
 		exit 1
 	fi
-	GCOV="gcov-${GCC_VERSION}"
+	GCOV="gcov-${GCC_VERSION}"
🧹 Nitpick comments (1)
tools/collect-coverage.sh (1)

143-146: Optional: Consolidate GCOVR version checks

The script currently uses two separate awk invocations to detect gcovr v5.0+ and v6.0+. Consider refactoring into a small helper function to DRY up the logic and make future version thresholds trivial to add:

add_gcovr_opt() {
  local min_version=$1 opt_key=$2 opt_val=$3
  if awk "BEGIN {exit !(${GCOVR_VERSION} >= ${min_version})}"; then
    echo "gcovr v${min_version}+ detected"
    GCOVR_OPTS+=("${opt_key}" "${opt_val}")
  fi
}

# then simply call:
add_gcovr_opt 5.0 "--exclude-lines-by-pattern" "${pattern}"
add_gcovr_opt 6.0 "--merge-mode-functions" "separate"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41915e9 and 1941bee.

📒 Files selected for processing (13)
  • CMakeLists.txt (3 hunks)
  • api/oc_client_api.c (2 hunks)
  • api/unittest/collectiontest.cpp (14 hunks)
  • api/unittest/discovery/discovery.cpp (8 hunks)
  • api/unittest/discovery/discovery.h (1 hunks)
  • api/unittest/discovery/discoveryobservetest.cpp (2 hunks)
  • api/unittest/etagtest.cpp (4 hunks)
  • api/unittest/resourcetest.cpp (6 hunks)
  • messaging/coap/engine.c (1 hunks)
  • messaging/coap/observe.c (2 hunks)
  • messaging/coap/unittest/observenotificationstest.cpp (10 hunks)
  • tests/gtest/Collection.h (1 hunks)
  • tools/collect-coverage.sh (2 hunks)
✅ Files skipped from review due to trivial changes (4)
  • api/unittest/discovery/discoveryobservetest.cpp
  • messaging/coap/observe.c
  • api/unittest/discovery/discovery.h
  • api/unittest/collectiontest.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • api/unittest/resourcetest.cpp
  • api/unittest/discovery/discovery.cpp
  • CMakeLists.txt
🧰 Additional context used
🧬 Code Graph Analysis (1)
messaging/coap/engine.c (2)
api/oc_helpers.c (1)
  • oc_string_len_unsafe (221-226)
api/oc_blockwise.c (1)
  • oc_blockwise_alloc_response_buffer (183-210)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: unit-tests (-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_RESOURCE_ACCESS_IN_RFO... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_DNS_LOOKUP_IPV6_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DOC_REPRESENTATION_REALLOC_E... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_RESOURCE_ACCESS_IN_RFO... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_DNS_LOOKUP_IPV6_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DOC_REPRESENTATION_REALLOC_E... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_RESOURCE_ACCESS_IN_RFO... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_DNS_LOOKUP_IPV6_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DOC_REPRESENTATION_REALLOC_E... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_RESOURCE_ACCESS_IN_RFO... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_DNS_LOOKUP_IPV6_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DOC_REPRESENTATION_REALLOC_E... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_RESOURCE_ACCESS_IN_RFO... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_DNS_LOOKUP_IPV6_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DOC_REPRESENTATION_REALLOC_E... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_RESOURCE_ACCESS_IN_RFO... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_DNS_LOOKUP_IPV6_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DOC_REPRESENTATION_REALLOC_E... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_RESOURCE_ACCESS_IN_RFO... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_DNS_LOOKUP_IPV6_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DOC_REPRESENTATION_REALLOC_E... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_RESOURCE_ACCESS_IN_RFO... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_DNS_LOOKUP_IPV6_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DOC_REPRESENTATION_REALLOC_E... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_RESOURCE_ACCESS_IN_RFO... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_DNS_LOOKUP_IPV6_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DOC_REPRESENTATION_REALLOC_E... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_RESOURCE_ACCESS_IN_RFO... / unit-test-with-cfg
  • GitHub Check: unit-tests (-DOC_DNS_LOOKUP_IPV6_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DOC_REPRESENTATION_REALLOC_E... / unit-test-with-cfg
🔇 Additional comments (22)
api/oc_client_api.c (2)

239-242: Added safety check for URI format before processing.

The code now correctly validates that the URI begins with a slash character before advancing past it, preventing potential issues with malformed URIs. This change improves robustness by making an implicit assumption explicit through the assertion.


447-447: Improved input validation for URIs.

Adding an assertion to verify that URIs start with a '/' character is a good defensive programming practice. This ensures that all URIs passed to the request function follow the expected format.

messaging/coap/engine.c (1)

996-999: Added proper URI validation and handling.

This change implements the same URI validation pattern seen in oc_client_api.c, ensuring consistency across the codebase. The assertion that the URI begins with '/' followed by adjusting the pointer and length is a good security practice that makes the code more robust against malformed inputs.

tests/gtest/Collection.h (2)

70-70: Function signature updated for safer string handling

The parameter types for NewCollection have been changed from std::string_view to const std::string &, which aligns with other similar changes across the codebase to unify string handling.


73-73: Updated string access method for C function compatibility

Changed from .data() to .c_str() to ensure null-terminated strings are passed to oc_new_collection, which is a C function that expects C-style strings. This is a safer approach that prevents potential issues with non-null-terminated strings.

messaging/coap/unittest/observenotificationstest.cpp (10)

62-68: String type consistency improvement

Changed from constexpr std::string_view to static const std::string for URI constants, which provides more consistent string handling and avoids potential issues when passing to C functions that expect null-terminated strings.


164-165: Updated resource definition to use std::string

Modified to use string directly in makeDynamicResourceToAdd call, consistent with the string type changes throughout the codebase.


186-187: Added explicit C-string conversion

Added .c_str() calls when passing strings to oc_collection_add_supported_rt and oc_collection_add_mandatory_rt, ensuring proper null-terminated strings for these C functions.


252-253: Using c_str() for C API compatibility

Updated to use .c_str() when passing the URI to oc_ri_get_app_resource_by_uri, which expects a C-style string.


269-269: Updated to pass std::string to RegisterObserve

Changed to pass the string directly to message::tcp::RegisterObserve, aligning with changes to use std::string throughout the codebase.


303-304: URI string handling consistency

Updated string handling when calling oc_get_collection_by_uri to use .c_str() for the URI parameter, ensuring proper null-terminated strings.


320-321: String handling in TCP message registration

Updated string handling in message registration to directly use the string constant, consistent with string type changes throughout the codebase.


363-364: Consistent string handling in observer registration

Similar to previous changes, updated string handling in the second test case to use consistent string passing approach.


481-483: Updated resource type usage

Changed to use string directly in resource type definition for collection resource, improving type consistency.


512-513: String handling consistency in dynamic resource

Updated string parameters in makeDynamicResourceToAdd to use the string directly rather than string_view, consistent with other similar changes.

api/unittest/etagtest.cpp (7)

80-84: Improved string type consistency

Changed from constexpr std::string_view to static const std::string for URI constants, providing more consistent string handling and avoiding potential issues when passing to C functions.


484-491: Enhanced string handling in dynamic resource creation

Updated string handling in the dynamic resource function calls to use string object references directly, improving type safety and consistency.


499-499: Local string type consistency

Changed the powerSwitchRT variable from string_view to string, maintaining consistency with other string handling changes throughout the codebase.


504-505: Added C-string conversion for C API calls

Added .c_str() calls when passing strings to oc_collection_add_supported_rt and oc_collection_add_mandatory_rt, ensuring proper null-terminated strings for these C functions.


512-513: String handling consistency in resource creation

Updated string parameters in makeDynamicResourceToAdd to use string objects directly instead of string_view, maintaining type consistency.


1054-1055: String handling improvement in collection URI lookup

Updated to use .c_str() when passing the URI to oc_get_collection_by_uri, ensuring proper null-terminated strings.


1063-1064: String handling consistency in link URI lookup

Updated to use .c_str() when passing the URI to oc_get_link_by_uri, ensuring proper null-terminated strings when interfacing with C functions.

@Danielius1922 Danielius1922 force-pushed the adam/feature/654-coverity-fixes-1 branch 3 times, most recently from 17b5a5c to 68ed56b Compare May 8, 2025 16:01
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
port/linux/ipadapter.c (1)

374-374: Keep space around bitwise AND operator for better readability.

The removal of the space before the & operator makes the code less readable. Most C style guides recommend spaces around binary operators.

-  if (*(uint32_t *)(RTA_DATA(attr))&IFA_F_TEMPORARY) {
+  if (*(uint32_t *)(RTA_DATA(attr)) & IFA_F_TEMPORARY) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b11e2be and b6be72c.

📒 Files selected for processing (2)
  • port/linux/ipadapter.c (3 hunks)
  • util/oc_compiler.h (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • util/oc_compiler.h
🔇 Additional comments (5)
port/linux/ipadapter.c (5)

536-555: Good refactoring: Extracted interface refresh logic into a reusable function.

This extraction improves code modularity and maintainability. The atomic operations are properly used to ensure thread-safe flag updates.


557-573: Well-designed wrapper functions for cleaner code.

These wrapper functions effectively encapsulate the compiler warning suppression, making the code more maintainable and following the DRY principle.


575-626: Well-structured function for handling interface addition events.

The function properly:

  • Validates input parameters
  • Handles both IPv4 and IPv6 cases with appropriate conditional compilation
  • Accumulates error status correctly
  • Uses the wrapper functions effectively

628-640: Clean implementation for interface removal handling.

Simple and focused function that properly handles the interface removal event with appropriate conditional compilation.


646-696: Excellent refactoring of the event processing function.

The function is now more modular and easier to understand by delegating specific event handling to dedicated functions. This improves:

  • Code readability
  • Maintainability
  • Testability
  • Separation of concerns

@Danielius1922 Danielius1922 force-pushed the adam/feature/654-coverity-fixes-1 branch from 7192f32 to bd2b556 Compare May 30, 2025 07:46
@coderabbitai
Copy link

coderabbitai bot commented May 30, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Danielius1922 Danielius1922 added the OCF Conformance Testing OCF Conformance Testing required label May 30, 2025
@ocf-conformance-test-tool ocf-conformance-test-tool bot removed the OCF Conformance Testing OCF Conformance Testing required label May 30, 2025
@Danielius1922 Danielius1922 requested a review from jkralik May 30, 2025 21:56
@Danielius1922 Danielius1922 added the OCF Conformance Testing OCF Conformance Testing required label May 31, 2025
Fix issue 448975: Resource leak in oc_endpoint.c
Fix issue 420846: Overflowed integer argument in plgd_dps_dhcp.c
Fix issue 487972: Copy into fixed sized buffer in cloud_server.c
Fix issue 55728: Out-of-bouds access in oc_client_api.c
Fix issue 58116: Out-of-bouds access in engine.c
Fix issue 58444: Out-of-bouds access in observe.c
Fix issue 72327: Out-of-bouds access in dps_security
Fix issues 73594, 73889: Out-of-bouds write in storage.c
Fix issue 55551: speculative execution data leak in linux/ipadapter.c
Fix issue 525128: Unused value in observe.c
Fix issue 525129: Unused value in oc_server_api.c
@Danielius1922 Danielius1922 force-pushed the adam/feature/654-coverity-fixes-1 branch from 52759ba to 5c1421c Compare June 2, 2025 16:39
@ocf-conformance-test-tool ocf-conformance-test-tool bot removed the OCF Conformance Testing OCF Conformance Testing required label Jun 2, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 2, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
36.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@Danielius1922 Danielius1922 merged commit beb13a5 into master Jun 2, 2025
343 of 379 checks passed
@Danielius1922 Danielius1922 deleted the adam/feature/654-coverity-fixes-1 branch June 2, 2025 18:17
@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants