[MegaLinter][valid] C code: missing NULL checks after malloc/calloc, sprintf usage, and needs a clang-format pass
#3,836 opened on 2026/07/24
Repository metrics
- Stars
- (160 個のスター)
- PR merge metrics
- (PR metrics pending)
説明
From the 2026-07-24 Analyze run, covering the only 2 C files in the repo: actions/instrument/job/forward.c and src/usr/share/opentelemetry_shell/agent.instrumentation.http/agent.injection.http_header.c. All classified as valid findings (bucket 1).
cppcheck: real robustness bugs (2 findings)
Missing NULL checks after allocation, each with a genuine null-pointer-dereference path if the allocation fails:
forward.c:19—original_command = malloc(total_length)(line 18) not checked before use at line 19forward.c:39,47,49—new_argv = calloc(...)(line 37) not checked before useagent.injection.http_header.c:238-242—my_key = calloc(...)(line 236) andmy_value = calloc(...)(line 237) not checked before use
cpplint: mostly real, two rules worth reconsidering
Findings across both files: sprintf → snprintf (3 occurrences, genuine buffer-overflow-avoidance suggestion — the C equivalent of a real security nit), line length > 80 chars (~15 occurrences), trailing whitespace, comment spacing, if-body-on-separate-line style.
Two sub-rules are Google-C++-style-guide-specific and may not be worth keeping for this project specifically:
legal/copyright— wants a// Copyright [year] <Owner>header in every file; this repo already has a top-levelLICENSE, so per-file headers may be considered redundantreadability/todo— wants// TODO(username): ...format
If you don't want those two, cpplint supports C_CPPLINT_ARGUMENTS: ["--filter=-legal/copyright,-readability/todo"] in .mega-linter.yml. Left as-is for now since it's a minor call either way.
clang-format: needs a pass (190 findings, both files)
Every line in both files is flagged — reads like clang-format has simply never been run on this code. clang-format -i actions/instrument/job/forward.c src/usr/share/opentelemetry_shell/agent.instrumentation.http/agent.injection.http_header.c should resolve the bulk of it in one shot.